in reply to Possible with a regex?
Depending on how much you can limit your input, one easy way would be to disallow [ in your URLs:
while ($test =~ m!\[img\]([^\[]+)\[\/img\]!g) { print "$1 \n"; }
If you really want to allow [ and ] in your tags as well, you can, I think, create some complex look-ahead regex that disallows for [img] to appear, by allowing for [ if it's not followed by i and allowing [i if it's not followed by m and allowing [im if it's not followed by g and so on:
while ($test =~ m!\[img\]((?:[^\[]+|\[[^i]|\[i[^m]|\[im[^g]|...)+\[\/i +mg\]!g) { print "$1 \n"; }
Personally, I would restrict the input to disallow [ in URLs or just split on /\[img\]/ and then discard all strings that don't contain [/img].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Possible with a regex?
by ultranerds (Hermit) on May 23, 2011 at 15:55 UTC |