question

dclaar avatar image
dclaar Suspended asked dclaar Suspended posted

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! 

iTestbug
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image
dclaar Suspended answered dclaar Suspended posted

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

Oh, 3.4.1.

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

YujieL avatar image
YujieL answered YujieL posted

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.

3 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image dclaar commented ·

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.

0 Likes 0 ·
unregex.fftc (3.9 KiB)
YujieL avatar image YujieL dclaar commented ·

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.

0 Likes 0 ·
dclaar avatar image dclaar YujieL commented ·

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 $.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.