C ++ Regex POSIX字符类有问题 [英] Trouble with C++ Regex POSIX character class

查看:66
本文介绍了C ++ Regex POSIX字符类有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个能够分析如下内容的正则表达式:

I'm trying to create a regex that is capable of analysing something like this:


002561-1415179671591i.jpg

002561-1415179671591i.jpg

第二部分是unix时间戳(在i之前),我需要提取它。我想出了以下语法,但是std :: regex甚至在我检查匹配项之前都会抛出regex_error,我不太确定出什么问题了。

The second part is a unix timestamp (before the i), and I need to extract that. I came up with the following syntax, but std::regex keeps throwing a regex_error before I even check for a match and I'm not too sure what's wrong.

这里是到目前为止,我得到的是:([[:d:])*-[[:d:]] *([:alpha:])\.jpg

Here's what I've got so far:([:d:])*-[[:d:]]*([:alpha:])\.jpg

引发错误的C ++代码行是正则表达式的构造函数

The C++ code line that throws the error is the constructor to regex

std::regex reg(regex_expr);

其中 regex_expr 是一个字符串,

真的很感谢您可以提供的帮助。

Really appreciate any help you can give.

编辑:我写了一篇catch部分,似乎我得到了以下错误代码

I wrote a try catch section, and it seems I'm getting the following error code

std :: regex_constants :: error_brack

编辑2:好的,即使经过缩减测试,我似乎仍然会收到错误:

Edit 2: Ok... seems I'm still getting the error even with a cut-down test:

([:alpha:])*

编辑3:

似乎我无法使用任何表达式。这里有更多信息。我在Kubuntu 14.04上使用clang ++ 3.5.0。

Seems I can't get any expression to work. Here's a bit more info. I'm using clang++ 3.5.0 on Kubuntu 14.04.

推荐答案

经过多次测试,无论出于何种原因,我都无法这个工作。无论如何,当我进行了boost时,我立即尝试了boost :: regex,它立即起作用,因此我认为与clang或此PC上的标准版本无关的事情不起作用。

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.

这篇关于C ++ Regex POSIX字符类有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆