in reply to Regex question - negatives
A few additional points:
I notice that you want \| in your output. If you use qq|...| to quote the string you'll need to escape "\|" with "\\\|", not "\|". "\\" to escape the "\" and "\|" to escape the pipe.
Alternatively, you could simplify matters and use a single quote syntax such as q{...} or any other delimiter that isn't in your string. \ will be taken literally, and the curly brace delimiters don't show up in your string so there is no need to escape the pipe or any other character.
If you know that bad tags end in double square braces you can dispense with the negative lookahead m{\[\[([^\[]+)\]\]}g The main thing to get rid of is that (.+) because "." matches everything including the end of tag character.
Revised code incorporating above points:
my $test = q{asdfas dfas dfas df asfd[[bad tag]] [[table]] asdfa sf as + [[asdf as f\|sfds]] as dfa sdf [[test new line]] foo}; while ($test =~ m{\[\[([^\[]+)\]\]}g) { print "FOO:<$1>\n"; } #output - same as required in OP FOO:<bad tag> FOO:<table> FOO:<asdf as f\|sfds> FOO:<test new line>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex question - negatives
by ultranerds (Hermit) on Jan 13, 2011 at 10:26 UTC |