googletest icon indicating copy to clipboard operation
googletest copied to clipboard

MatchesRegEx doesn't seem to work.

Open ronaldfenner opened this issue 5 years ago • 9 comments

I'm trying to to use MatchesRegEx to match a date but it always returns failed. I'm run this test on MacOS so it's a posix system but i'm just trying to use the simplified syntax so i don't have to have 2 versions.

The code I'm trying to use is EXPECT_THAT(Log::GenerateISO8601Time(true), ::testing::MatchesRegex("\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ"));

I figured maybe it wasn't correct so i went to a simple test for just EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("\\d+"));

It also doesn't work.

This does work though EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex("2020")); EXPECT_THAT(std::string("2020"), ::testing::MatchesRegex(".+"));

I did browse through the chromium repo looking at its use of MatchesRegEx. I'm also using bazel as the build system so it build gtest as a dependency of the test.

ronaldfenner avatar Oct 27 '20 04:10 ronaldfenner

For me, it works with [0-9] instead of \\d (using current trunk build: a3460d1aeeaa43fdf137a6adefef10ba0b59fe4b)

theShmoo avatar May 28 '21 11:05 theShmoo

I found this issue only appeared on Linux + gcc. \d works on Windows.

tntljc avatar Sep 26 '22 15:09 tntljc

Also having this issue on 1.11, using [0-9] fixed it but was unpleasant to debug

Same problem. EXPECT_THAT("name 1", MatchesRegex("name \\d+")); fails!

GCUGreyArea avatar Jan 08 '23 11:01 GCUGreyArea

\d+ works for me on Windows, but not [0-9]+ :(

schmidt-sebastian avatar Mar 01 '23 23:03 schmidt-sebastian

As per the documentation, Windows works differently:

On Windows, GoogleTest uses its own simple regular expression implementation. It lacks many features. For example, we don't support union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and repetition count ("x{5,7}"), among others. Below is what we do support (A denotes a literal character, period (.), or a single \ escape sequence; x and y denote regular expressions.):

https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax

Kikadass avatar Apr 11 '23 02:04 Kikadass