Re: the only difference is the 'x' after '/g'
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 31 Mar 2006 05:21:38 -0800
[top posting corrected - please fix your quoting style]
Tom Arnall wrote:
On Thursday 30 March 2006 05:15 am, Hans Meier (John Doe) wrote:
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.
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.
i need the blank in 'From [' etc in order to distinguish it from the strings
with 'From:' one solution to the problem, btw, is to use '\s' instead of a
literal blank. does this behavior rank as a bug in perl?
You're not making any sense. You added the /x modifier. The ONLY
effect this has is to make the pattern match ignore white spaces. If
you don't want the pattern match to ignore white spaces, why did you
add the /x modifier? This is not a bug - this is the EXACT effect this
modifier is supposed to have!
You need to read the documentation, rather than just typing random
characters into your code and then complaining when they have the exact
effect they're supposed to have.
If for some reason you want to use the /x modifier, but still want to
recognize a particular whitespace character, prepend that whitespace
with a backslash.
Paul Lalli
.
- References:
- the only difference is the 'x' after '/g'
- From: Tom Arnall
- Re: the only difference is the 'x' after '/g'
- From: Hans Meier
- Re: the only difference is the 'x' after '/g'
- From: Tom Arnall
- the only difference is the 'x' after '/g'
- Prev by Date: Re: the only difference is the 'x' after '/g'
- Next by Date: Really simple XML question
- Previous by thread: Re: the only difference is the 'x' after '/g'
- Next by thread: Re: the only difference is the 'x' after '/g'
- Index(es):
Relevant Pages
|