Re: the only difference is the 'x' after '/g'
- From: kloro@xxxxxxx (Tom Arnall)
- Date: Fri, 31 Mar 2006 08:04:39 -0800
Hans, got it: /x tells sys' to ignore all white space, not just \n. thanks
very much. and thanks to the people who make possible this great mailing
list. ;o)
tom arnall
north spit, ca
On Friday 31 March 2006 07:29 am, Hans Meier (John Doe) wrote:
tom arnall am Freitag, 31. März 2006 09.56:
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?
No, absolutely not.
To make your distiction, you *have* to use the \s with the /x modifier;
without, you can use either.
The /x modifier's aim is to allow readable *formatting* of complex regexes
with spaces, line brakes, comments (#). ' ' in this case is irrelevant for
the matching. Look at the beginning of
perldoc perlre
hth!
Hans
[bottom post order:]
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.
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
.
- References:
- the only difference is the 'x' after '/g'
- From: Tom Arnall
- Re: the only difference is the 'x' after '/g'
- From: Tom Arnall
- Re: the only difference is the 'x' after '/g'
- From: Hans Meier
- the only difference is the 'x' after '/g'
- Prev by Date: Re: sending email problem....
- Next by Date: How to printout matching pattern in command line
- 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
|