in reply to html regex problem
(.+)? (optionally match one or more characters)
should be
(.+?) (match one or more characters non-greedily)
For example,
$saved_page = <<'__EOI__'; </a><br>Haunted Woods 1.13 WC Piece<br> <b> </a><br>Moo Moo 1.23 WD Piece<br> <b> </a><br>Foo Bar 1.14 WC Piece<br> <b> __EOI__ push (@items, $1) while $saved_page =~ m#</a><br>(.+?)<br> <b>#g; print("$_\n") foreach @items;
outputs
Haunted Woods 1.13 WC Piece Moo Moo 1.23 WD Piece Foo Bar 1.14 WC Piece
Update: If there can be newlines, don't forget to use /.../gs instead of /.../g.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |