Re: the only difference is the 'x' after '/g'
- From: security.department@xxxxxxxx (Hans Meier)
- Date: Thu, 30 Mar 2006 14:15:17 +0100
tom arnall am Donnerstag, 30. März 2006 12.36:
the following code:
my (@main);
$_="
From a
From: b
From: c
From: d
";
@main = /From [^\n]*?\n.*?(From: .*?\n).*?/gx;
print "@main";
print "------------------------------\n";
@main = /From [^\n]*?\n.*?(From: .*?\n).*?/g;
print "@main";
produces:
From: b
From: d
------------------------------
From: b
the only difference between the two regex lines is the 'x' after '/g' in
the first of the two regex lines.
indeed :-)
And your question could be: Why does this produce different results?
There's an additional difference on the semantic level: spaces in the 1st
regex are irrelevant. Look at the first regex space: in the 2nd regex, it
matches (only) in "From a", but not in "From: c", whereas the 1st regex
matches "From a" *and* "From: c".
/From[^\n]*?\n.*?(From: .*?\n).*?/gx;
and
/From[^\n]*?\n.*?(From: .*?\n).*?/g;
produce both the same output.
hth!
Hans
.
- Follow-Ups:
- Re: the only difference is the 'x' after '/g'
- From: Tom Arnall
- Re: the only difference is the 'x' after '/g'
- References:
- the only difference is the 'x' after '/g'
- From: Tom Arnall
- the only difference is the 'x' after '/g'
- Prev by Date: the only difference is the 'x' after '/g'
- Next by Date: Re: store Array in hash ?
- Previous by thread: the only difference is the 'x' after '/g'
- Next by thread: Re: the only difference is the 'x' after '/g'
- Index(es):
Relevant Pages
|