in reply to Regex question - either starts, or has newline prefixing?
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)/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex question - either starts, or has newline prefixing?
by ultranerds (Hermit) on Jul 13, 2009 at 13:41 UTC | |
by ultranerds (Hermit) on Jul 13, 2009 at 13:56 UTC | |
by johngg (Canon) on Jul 13, 2009 at 19:28 UTC |