Skip to content

Commit fc72292

Browse files
committed
Change to actually use POSIX extended regular expressions
as documented, not ECMAscript regexes (the default in C++ STL). Note that this implies that '.' matches newlines.
1 parent 043fdb6 commit fc72292

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

doc/format-spec.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ The following commands are available:
123123
<dt><tt>REGEX(&lt;value&gt; str [, &lt;variable&gt; name])</tt></dt>
124124

125125
<dd>Match the extended regular expression 'str', which must be of
126-
string type. Matching is performed greedily, while '.' (a dot)
127-
does not match a newline. Optionally assign the matched string to
128-
variable 'name'.</dd>
126+
string type. Matching is performed greedily and '.' (a dot)
127+
matches a newline, use <tt>[^\n]</tt> to work around this.
128+
Optionally assign the matched string to variable 'name'. Note that
129+
since some string characters have to be escaped already, you might
130+
need to double escape them in a regex string. For example, to
131+
match a literal backslash, enter <tt>\\\\</tt>.</dd>
129132

130133
<dt><tt>ASSERT(&lt;test&gt; condition)</tt></dt>
131134

libchecktestdata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ void checktoken(command cmd)
10891089

10901090
else if ( cmd.name()=="REGEX" ) {
10911091
string str = eval(cmd.args[0]).getstr();
1092-
regex regexstr(str);
1092+
regex regexstr(str,regex::extended);
10931093
match_results<string::const_iterator> res;
10941094
string matchstr;
10951095

tests/testprog23.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SET(foo="bar.*")
22
STRING(foo) NEWLINE
3-
REGEX(foo) NEWLINE
3+
REGEX(foo) # Note that '.' also matches newlines and ERE is greedy.

tests/testprog25.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
REGEX("\\\\(foo|(bar|baz))\
2-
x\n[\\.-\\}]") NEWLINE
2+
x\n[.-}]") NEWLINE

tests/testprog28.err

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
REGEX(".*") NEWLINE
1+
# Note that ERE '.' also matches newlines!
2+
REGEX("[^\n]*") NEWLINE
23
SET(a=1/2)
34
ASSERT(a == 0.5)

tests/testprog28.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
REGEX(".*") NEWLINE
1+
# Note that ERE '.' also matches newlines!
2+
REGEX("[^\n]*") NEWLINE
23
SET(a=1/2.)
34
ASSERT(a == 0.5)

0 commit comments

Comments
 (0)