[Tutor] search/match file position q

Alan Gauld alan.gauld at btinternet.com
Wed Oct 8 01:18:32 CEST 2014


On 07/10/14 20:53, Clayton Kirkwood wrote:

> In this case, I was able to determine which line I
 > was interested in because it had a
 > specific marker.
 > From that point, I knew specific markers to look
 > for for each desired field.

> I thought the desired parenthesis couple was assigned
 > to the variable at the beginning of the match line.

I'm not quite sure what you mean by that.

> I thought that regex's Were meant to skip over
 > unwanted detritus and grab only the desired
 > match with in the parentheses.

Not quite. They don't "skip over" unwanted detritus.
The detritus is either part of the matched pattern
or it's not. regex find defined patterns they don't
find undefined patterns. The skipping over happens
as a side effect of looking for the pattern, it's not
a design goal of itself.

And the reason regex are often described as a weapon
of last resort is because it's infernally difficult
to define exactly the right pattern for anything
non-trivial. And especially in things like HTML
where it may even be impossible to get it right.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list