开发者

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

开发者 https://www.devze.com 2022-12-16 00:23 出处:网络
I couldn\'t find anything regarding this on http://msdn.microsof开发者_运维问答t.com/en-us/library/bb982727.aspx.

I couldn't find anything regarding this on http://msdn.microsof开发者_运维问答t.com/en-us/library/bb982727.aspx.

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


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).


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).


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]+


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 ..

0

精彩评论

暂无评论...
验证码 换一张
取 消