There's nothing here to say "stop at a new line"
Without the modifiers the string looks like:
'one upon a time\nonce upon a time'
Which matches your regex the same way 'once upon a time once upon a
time' would.
without the /g you'll match on the first one.
I guess the question is, what do you want it to do?
Do you want @store to equal ('once', 'once')?
then you might try (untested):
while ($str =~ /(once)/g) {
push @store, $1;
}
or
while ($str =~ /(once)[^\r\n]+$/gm) {
push @store, $1;
}
But I'm not sure what this second one will give you that the first
doesn't.
On Jun 1, 2007, at 4:54 AM, Sharan Basappa wrote:
I have a script as follows :
$str = "once upon a time
once upon a time";
@store = $str =~ m/(once)/g;
print @store ;
This outputs "onceonce"
How come regex is searching beyond newline. I thought the search will
stop after first once.
When I replace /g with /m, the output I get is "once", but I
thought /m will
tell regex at multiple lines for match.
Also when I replace /g with /s, I still get output "once"
Can someone demystify this for me ?
Is my assumption that regex will stop after encountering first
newline is
applicable only when dot* type of regex is used ?
Thanks,
Sharan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/