- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 04:39 PM
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!
Solved! Go to Solution.
Re: multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 04:44 PM
Setting the regex to ^.*$ causes it to only return one response. Still calling bug. :-)
Oh, 3.4.1.
Re: multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 05:22 PM
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.
Re: multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 05:25 PM
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.
Re: multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 06:14 PM
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.
Re: multiple results for regex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2009 06:18 PM
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 $.
