Home > Archive > PERL Beginners > September 2006 > regex help needed
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Gerald Wheeler 2006-09-27, 6:59 pm |
| 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
/^[^\#]*ab2/,@lines
Thanks
| |
| nobull67@gmail.com 2006-09-27, 6:59 pm |
|
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.
| |
|
| On Wed, 27 Sep 2006 13:11:17 -0600
"Gerald Wheeler" <GWHEELER@uc.usbr.gov> 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
>
> /^[^\#]*ab2/,@lines
Presumeably you want a match against '/ab1'
In which case you might just get by with /\/ab1/
But you may need to provide a few more specifications and example data
Owen
|
|
|
|
|