Trouble with C++ Regex POSIX character class

不想你离开。 提交于 2019-12-02 00:07:26

Not sure that [:d:] can stand for [:digit:]. [EDIT] (It seems it's possible)

When you use a POSIX character class, it must be enclosed in a character class like that:

[[:digit:]]

(This syntax allows to compose other classes [[:digit:]ab])

so:

std::string regex_expr = "([[:digit:]]*)-([[:digit:]]*)([[:alpha:]])\\.jpg";

or if you use the basic mode:

std::string regex_expr = "\\([[:digit:]]*\\)-\\([[:digit:]]*\\)\\([[:alpha:]]\\)\\.jpg";

I would rather use the perl-compatible syntax instead of character classes:

\d+-(\d+)[a-z]*\.jpg

After many tests, for whatever reason, I couldn't get this to work. As I had boost anyway, I tried out the boost::regex and it worked straight away, so I presume that something to do with either clang, or the version of the standard on this pc just wasn't working.

So simply put, tried boost and it worked straight away. Not much of an answer, but I guess that's how things go sometimes.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!