On Sep 12, 2005, at 8:14, Keenan, Greg John (Greg)** CTR ** wrote:

meteor    (L, 4) (G,24)
rocket    (J,19) (D,35)
aulan     (E,28) (E, 2)
aupbx     (B,32) (O,10)

And I need to work with the chars between the brackets after I've found the string on the left e.g. if my $host variable matches rocket then I need to get J and 19 and D and 35 into an array or their own seperate variables.

I have been going around in circles with the regex. I have tried escaping the round brackets with \, anchoring the string to the end with \z and a
multitude of other combos of \D \d \w . \s etc.

Sometimes, when you control the input strings is easier to _relax_ the regex than to write the most specific one, because sometimes with a less constrained regex we are done.

In this case you could probably just do:

    my @c = $line =~ /\Q$host\E\W+(\w+)\W+(\w+)\W+(\w+)\W+(\w+)/;

If you are looking for something after some stuff in the string a useful technique in the toolbox is to move the regexp engine's pointer there with m//g:

$line =~ /\Q$host/g; # /g in scalar context to anchor the next match

and then use \G. In our example that would be, say:

    @c = $line =~ /\G\W+(\w+)/g;

but in this case I'd go with the first option, since I find it more clear.

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to