Reply
Regular Contributor
dclaar
Posts: 1,128
Registered: 09-18-2008
0
Accepted Solution

multiple results for regex

I have a simple analysis rule:

analyze regex .* (line mode not checked, full match, declare issue if no matches found)

   assert $value eq ""

      if true, fail

      if false, OK

 

When I run this, I get two assertions: One with all of the text from the command, and one with nothing in it. So I pass and fail the analysis.

 

This is just wrong. If I ask for everything, I should get everything. And isn't that what .* means?

 

I'm really just trying to see if I got anything back, so I'm open to some other way of doing that. But this still looks like a bug! 

Regular Contributor
dclaar
Posts: 1,128
Registered: 09-18-2008
0

Re: multiple results for regex

Setting the regex to ^.*$ causes it to only return one response. Still calling bug. :-)

Oh, 3.4.1.

Fanfare
YujieL
Posts: 187
Registered: 09-03-2008
0

Re: multiple results for regex

it sounds like a bug...what is the response/text that you're doing the analysis on? I'd like to try it myself and see what the analysis returns.

Regular Contributor
dclaar
Posts: 1,128
Registered: 09-18-2008
0

Re: multiple results for regex

Attaching test case. Really just call foo

 

foo

write this

write is

write a

write test

 

Of course, in real life, it was the output of a command, but the above/attached will reproduce it.

Fanfare
YujieL
Posts: 187
Registered: 09-03-2008

Re: multiple results for regex

I see the same behavior, but this doesn't look like a bug.  Some regex testers online will show you the number of matches, and it will find two matches, one which is the entire string, one which is an empty string.  I'm no expert on how regex engine works, but it's quite possible that the engine starts matching at position 0, and it finds "thisisatest", then it tries to find a second match starting at position 11, which is just an empty string. Since .* matches anything, it would match the empty string.

Regular Contributor
dclaar
Posts: 1,128
Registered: 09-18-2008
0

Re: multiple results for regex

Wow, I guess you're right. Even perl does it that way:

 

perl -le '$a="this is a test";$a=~s/.*/a/g;print $a';
aa

 Learn something new every day! I guess in perl, I've always anchored the expression with ^ and $.