It occurred to me that the snippet I posted, even if it does what you want, it probably it doesn't tell you much about why yours is not working, so here are just a couple of comments on your regexps. The /m modifier is useful only if you are matching a string that contains multiple lines; it tells perl to match ^ and $ to the beginnings and ends of lines. Study this example and you will see what I mean:

use strict; use warnings; my $string = "foo\nbar\nbaz\n"; print "1st match ", $string =~ /^bar/ ? "succeeded\n" : "failed\n"; print "2nd match ", $string =~ /^bar/m ? "succeeded\n" : "failed\n"; print "3rd match ", $string =~ /bar$/ ? "succeeded\n" : "failed\n"; print "4th match ", $string =~ /bar$/m ? "succeeded\n" : "failed\n"; __END__ 1st match failed 2nd match succeeded 3rd match failed 4th match succeeded
Next, the /g modifier makes sense only if you are matching the same string multiple times want to match the same regexp multiple times in the same string. For example, using the same string as for the example above:
while ( $string =~ /(a\w+)/g ) { print "$1\n"; } __END__ ar az
Lastly, the expression $i =~ s/.//gm simply sets $i to the empty string (in this case the /m modifier does nothing; you'd get the same result without it). I don't think this gets you anything, but if that's what you wanted to do, it is simpler to just assign the empty string: $i = ''.

Update: Corrected sloppy wording. Thanks to Roy Johnson.

the lowliest monk


In reply to Re: regex man they are tough by tlm
in thread regex man they are tough by tgolf4fun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.