in reply to Re: Matching n characters with m//g
in thread Matching n characters with m//g

Thanks Ken, I am indeed attempting to extract than many characters, so the utilisation of the curly brackets in this instance is correct. Thanks for following up though, appreciated!

Replies are listed 'Best First'.
Re^3: Matching n characters with m//g
by kcott (Archbishop) on Feb 22, 2016 at 06:05 UTC

    OK, it looks like I confused "{32760}" and "{234565}"; however, I don't see "{234565}" anywhere in your code, although you state:

    "... when I come to the part "RFC822.TEXT {234565}" I now need to read exactly 234565 from the string."

    The string data you posted is multi-line (i.e. it contains newlines) so you'll need the 's' modifier if you want '.' to match newlines as well as other characters (see perlre: Modifiers). Here's a rough example of what I think you're looking for:

    $ perl -wE 'my $x = qq{abcd\nefgh\nijkl}; say ">$x<"; say ">$1<" while + $x =~ /(.{3})/gs' >abcd efgh ijkl< >abc< >d e< >fgh< > ij<

    [Note how I've wrapped each string in angle brackets, so that you can see not just the start and end of each string, but also the placement of newlines within them.]

    The caret (in your original code) still looks dubious. If it isn't, and you want to match the start of lines (in a multi-line string), you'll need the 'm' modifier (see perlre: Modifiers). Also, if you want to match the start of the entire string, use '\A' (see perlre: Assertions).

    — Ken