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
    Thanks - that gave me a fatal error though:

    Sequence (?x...) not recognized in regex; marked by <-- HERE in m/(?x <-- HERE k+/

    Cheers

    Andy
      Never mind - I decided to take the slightly more long-winded route, and use:

      my @headers; my @tmp_split = split /\n/, $post->{post_message}; foreach (@tmp_split) { chomp; if ($_ =~ /^\=\=([a-z0-9_ &\[\]ÀÂÄàâäÇçÉÊÈËéêèëÏÌÎïìîÖÔÒöôòÜÛÙ +üûùA-Z?!;«»()"\s]+)\=\=$/) { my $header = $1; # print qq|ok, got header of $1<br />\n|; my $section = get_section_code($1,$post->{post_message}); my @tmp_2 = split /\n/, $section; my @subheaders; foreach my $tmp (@tmp_2) { # print qq|checking sub-section for $header, line is: " +"| chomp; if ($tmp =~ /^\=\=\=([a-z0-9_ &\[\]ÀÂÄàâäÇçÉÊÈËéêèëÏÌÎ +ïìîÖÔÒöôòÜÛÙüûùA-Z?!;«»()"\s]+)\=\=\=$/) { push @subheaders, $1; } } push @headers, { Section => $header, SubLoop => \@subheade +rs }; @subheaders = undef; @tmp_2 = undef; } }


      Seems to work fine :)

      Cheers

      Andy

      Sorry, that's because there's a typo in my code :-(

      This

      {(?x}

      Should have been this

      {(?x)

      Cheers,

      JohnGG