RE's question..

H

howa

hi guy,

i have a very simple question about RE:

RE: /.*/

String: "this is a test"

why there is a 2 matches, rather than just 1 ?

thanks.

howa
 
M

MSG

howa said:
hi guy,

i have a very simple question about RE:

RE: /.*/
it matches almost any thing, be it an one letter string,
or a million character string in one line, even an empty
stirng. /.*/ is pretty much never used by itself.
Please read more about regex quantifier, things
like * + ? and make sure you understand their difference.
String: "this is a test"

why there is a 2 matches, rather than just 1 ?
Are your printing something here like return code? I don't
think people can understand what you mean without seeing
your program code.
thanks.

howa

Also please always do
use strict;
use warnings;
 
G

Gunnar Hjalmarsson

howa said:
i have a very simple question about RE:

RE: /.*/

String: "this is a test"

why there is a 2 matches, rather than just 1 ?

Do you mean that e.g.

print scalar( () = "this is a test" =~ /.*/g ), "\n";

outputs:
2

If you do, it's related to the fact that

print scalar( () = '' =~ /.*/g ), "\n";

outputs:
1
 
C

ced

Gunnar said:
Do you mean that e.g.

print scalar( () = "this is a test" =~ /.*/g ), "\n";

outputs:
2

Without 'g', this also prints '1'.
If you do, it's related to the fact that

print scalar( () = ''" =~ /.*/g ), "\n";

outputs:
1

But, with or without 'g', this prints '1'. This suggests a bug or
mis-feature IMO
since the regex is matched against a constant in both cases.
 
G

Gunnar Hjalmarsson

Without 'g', this also prints '1'.

So? Without the /g modifier, the return value of the m// operator is
either true or false, so those results are not comparable.
But, with or without 'g', this prints '1'. This suggests a bug or
mis-feature IMO
since the regex is matched against a constant in both cases.

No.

In the first case (with the /g modifier), it first matches the whole
string, and then the nullstring. In the second case, it simply matches
the nullstring.
 
T

Tad McClellan

howa said:
i have a very simple question about RE:

RE: /.*/

String: "this is a test"

why there is a 2 matches, rather than just 1 ?


There are not 2 matches there, so then the question becomes:

What makes you think that there are 2 matches?

Please post a short and complete program that we can run, that
demonstrates your problem, and we can surely explain it to you.
 
R

robic0

So? Without the /g modifier, the return value of the m// operator is
either true or false, so those results are not comparable.


No.

In the first case (with the /g modifier), it first matches the whole
string, and then the nullstring. In the second case, it simply matches
the nullstring.

Now theres something to worry about.
If a tree falls in the woods does it make a sound?
 
R

robic0

There are not 2 matches there, so then the question becomes:

What makes you think that there are 2 matches?

Please post a short and complete program that we can run, that
demonstrates your problem, and we can surely explain it to you.

Moreover, if there are 2 matches there, how can they be seperately captured?
If in scalar context the engine reports 2, shouldn't they be able to be captured
independently? Or if not, how would you know when to decrement the scalar counter?
 
U

Uri Guttman

"r" == robic0 <robic0> writes:

r> If a tree falls in the woods does it make a sound?

if you post here, did you use any live neurons?

uri
 
C

ced

Gunnar said:
So? Without the /g modifier, the return value of the m// operator is
either true or false, so those results are not comparable.


No.

In the first case (with the /g modifier), it first matches the whole
string, and then the nullstring. In the second case, it simply matches
the nullstring.

Yes, that's correct. I didn't recall that empty paren's worked that
way
without backref's.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top