If I've understood correctly, you might want to try a look-behind assertion. Also, you can use a quantifier, capture and back-reference for your equals signs. It looks like you need to preserve your first capture as it will be obliterated by subsequent matches. Something like (not tested)
... my $rxHeader = qr {(?x) (?: (?<=\A) | (?<=\n) ) ([=]{2,}) ([ your big character class ]+) \1 }; ... while ( $post->{ post_message } =~ m{$rxHeader}g ) { my $section = get_section_code( $2 ,$post->{ post_message } ); my @subheaders; while ( $section =~ m{$rxHeader}g ) { push @subheaders, $2; ... } push @headers, { Section => $section, SubLoop => \@subheaders } }
I hope I've understood correctly and this is useful.
Cheers,
JohnGG
Update: Fixed typo, s/behaind/behind/
Update 2: Fixed typo in code, s/{(?x}/{(?x)/
In reply to Re: Regex question - either starts, or has newline prefixing?
by johngg
in thread Regex question - either starts, or has newline prefixing?
by ultranerds
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |