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:
Next, the /g modifier makes sense only if youuse 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
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 = ''.while ( $string =~ /(a\w+)/g ) { print "$1\n"; } __END__ ar az
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |