Re: regex help needed
- From: "nobull67@xxxxxxxxx" <nobull67@xxxxxxxxx>
- Date: 27 Sep 2006 16:27:12 -0700
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.
.
- References:
- regex help needed
- From: Gerald Wheeler
- regex help needed
- Prev by Date: Re: --compare current date file with previous day
- Next by Date: Re: regex help needed
- Previous by thread: regex help needed
- Next by thread: Re: regex help needed
- Index(es):
Relevant Pages
|
|