0

I was trying to use both pcre and re2 and I came up with the following observation.

When I give the string as

"ab cd"

and the pattern as

"^[^c]"

re2 returns NO MATCH but its actually a match.

That is to say when I type this RE2::FullMatch("ab cd", RE2("^[^c]")) I get FAIL/No Match.

Please let me know if I am going wrong somewhere or what is the problem?

Atanu
  • 61
  • 2
  • 12
  • I suspect `FullMatch` means the engine tries to match the _whole_ regex with the _whole_ string, and discards any partial match. – Jerry Sep 23 '13 at 10:00
  • @Jerry It is a match right? The **whole** string does match with the **whole** pattern. Atleast for all other regex's its true isn't it? – Atanu Sep 23 '13 at 10:04
  • 1
    No, it doesn't match the whole string. To match the whole string, you might have to use something like ^[^c]+c[^c]+$. And I know only one regex that it's true (i.e. matches only if whole pattern matches whole string): Java's .matches method and Python's `.match`. There may be more, but not in C#, Javascript, Perl, PHP AFAIK. – Jerry Sep 23 '13 at 10:23

1 Answers1

3

RE2::FullMatch matches the entire string, like Jerry says.

There are two basic operators: RE2::FullMatch requires the regexp to match the entire input text, and RE2::PartialMatch looks for a match for a substring of the input text, returning the leftmost-longest match in POSIX mode and the same match that Perl would have chosen in Perl mode.

https://code.google.com/p/re2/wiki/CplusplusAPI

seanmcl
  • 9,740
  • 3
  • 39
  • 45