in reply to Regex Pop Quiz with .*, /g, and /s
I guess I generally don't replace nothing with something. Usually when I use * I'm either just skipping over white space (or the moral equivalent), or I replace any pattern than has * in it with itself. That is, something like s/A(.*)B/C${1}D/g;
Generally, I also try to constrain my patterns more, so I usually avoid constructs like ".*" or "*?", and would write something like s/A([^B]*)B/C${1}D/g;
The /s doesn't seem to have anything to do with it, except that, of course, you included a \n in your string. For example,
Now string is "gogobgo".my $string = "aaab"; $string =~ s/a*/go/g;
|
---|