in reply to I match a pattern in regex, yet I don't get the group I wanted to extract for some reason
If I run:
use strict; use warnings; my $tagl = do {local $/; <DATA>}; if($tagl =~ /<div class=\"soda.*?>(.*?)<\/div>/ism) { my $grp = $1; print "'$grp'\n"; } __DATA__ <div class="soda odd"> Power. Grace. Wisdom. Wonder. </div> <div class="soda even"> Wonder. Power. Courage. </div> <div class="soda odd"> The future of justice begins with her </div>
it prints:
' Power. Grace. Wisdom. Wonder. '
Maybe what you are trying to match or the regex you are using isn't what you have posted?
Note that parsing HTML/XML using regexen is generally a really bad idea. You've been told this several times already. Just in case you've forgotten why, you might like a refresher with Why a regex *really* isn't good enough for HTML and XML, even for "simple" tasks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I match a pattern in regex, yet I don't get the group I wanted to extract for some reason
by jcb (Parson) on Jan 13, 2021 at 00:42 UTC | |
|
Re^2: I match a pattern in regex, yet I don't get the group I wanted to extract for some reason
by SergioQ (Scribe) on Jan 12, 2021 at 16:44 UTC | |
by hippo (Archbishop) on Jan 12, 2021 at 17:40 UTC |