in reply to How to escape parens for grep
Anyway, the way to set up a regex to capture the pieces you want involves ignoring or escaping the regex-special characters (the parens in this case) -- something like this would do:
(that is, if you want the value of $protocol to be a string consisting of comma-separated numbers, as opposed to something else)$_ = "tethereal (proto 6 or 17) and src host suntest1 and dst host sun +test2 -w /tmp/dumpfile"; ( /\(proto ([^)]+)\) and src host (\S+) and dst host (\S+) -w (\S+)/ ) and ( $protocol, $srchost, $dsthost, $dir ) = ($1,$2,$3,$4); $protocol =~ s/ or /,/g;
Note the backslashes in front of the open and close parens that are intended to match actual parens in the string.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to escape parens for grep
by swaroop (Beadle) on Aug 15, 2005 at 01:44 UTC | |
by davidrw (Prior) on Aug 15, 2005 at 01:52 UTC |