Is there any way to have dot (.) match newline in C++ TR1 Regular Expressions?
Asked Answered
T

4

13

I couldn't find anything regarding this on http://msdn.microsoft.com/en-us/library/bb982727.aspx.

Maybe I could use '[^]+' to match everything but that seems like a hack?

Transit answered 12/1, 2010 at 21:24 Comment(1)
Dot-all? https://mcmap.net/q/908104/-boost-regex-dotall-flagScarberry
H
14

Boost.Regex has a mod_s flag to make the dot match newlines, but it's not part of the TR1 regex standard. (and not available as a Microsoft extension either, as far as I can see)

As a workaround, you could use [\s\S] (which means match any whitespace or any non-whitespace).

Halflight answered 12/1, 2010 at 21:32 Comment(0)
F
9

As C++ regular expressions appear to be based on ECMAScript regular expressions, the answer to the recent question about the same thing in JavaScript may help you.

[^] should work, but if you want something a little more clear and less hackish, you could try (.|\n).

Felly answered 12/1, 2010 at 21:38 Comment(0)
B
5

One trick people use is a character class containing anything that is not the null character. The null character is expressed in hex. It looks something like this:

[^\x00]+
Bestow answered 12/1, 2010 at 21:31 Comment(0)
G
1

You can switch to a non-ECMA flavor of regular expression (there are a number of flags to control regext flavor). Any POSIX regex should, if I recall correctly, match a newline to ..

Governor answered 12/1, 2010 at 22:0 Comment(1)
This works for example with extended regular expressions on Linux with gcc and on macOSX with Apple clang. Sadly, it does not work with Visual Studio, at least not with 2019 v16.8.0 that I tried. Therefore its not a generic solution.Strutting

© 2022 - 2024 — McMap. All rights reserved.