Re: regex help needed




Gerald Wheeler wrote:
I am looking for: ab1 in line1
and looking for: ab2 in line 2

actually ab1 and ab2 immediately follow the last "/" (there are
numerous "/" on the line (w/o quotes))

These are not working. can some explain what these say and what they
should say (syntax) to return the results I'm looking for: if ab1/ab2
are in the line, return true.

/^[^\#]*ab1/,@lines

This looks to see if the string in $_ starts with a series of
characters other than # followed by ab1. So $_='xxxxxab111111' would
match but $_='/1/2/3/#/ab1' would not.

What happens next depends on context. In a scalar context it throws
away this result an counts the number of elements in the array @lines.

In a list context it constucts a list consiting of the success code of
the match followed by the contents of @line.

/^[^\#]*ab2/,@lines

As above but with 'ab2' instead of 'ab1'.

If you want to check if the first element in @line contains ab1 then

$line[0] =~ /ab1/

If you want to check if the second element in @line contains ab2 then

$line[1] =~ /ab2/

Note: there's a more efficient but less readable method using index().

If that's not what you wanted (and somehow I suspect it isn't) then
you'll need to say what it is that you want.

.



Relevant Pages