Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
std::regex与g+一起失败+;?_Regex_C++11 - Fatal编程技术网

std::regex与g+一起失败+;?

std::regex与g+一起失败+;?,regex,c++11,Regex,C++11,我试图使用C++11的正则表达式来完成一个非常简单的过滤任务,但我无法让它按照我想要的方式工作。所以我开始编写一个单独的演示程序 问题是最简单的事情都失败得很惨。例如: #包括 #包括 #包括 int main() { 向量输入; 输入。推回(“1”); 输入。推回(“123”); 输入。推回(“a”); 输入。推回(“苹果”); 输入。推回(“:apple3.worm”); std::字符串模式(“[0-9]”); std::regex r(模式,std::regex_常量::grep); 用

我试图使用C++11的正则表达式来完成一个非常简单的过滤任务,但我无法让它按照我想要的方式工作。所以我开始编写一个单独的演示程序

问题是最简单的事情都失败得很惨。例如:

#包括
#包括
#包括
int main()
{
向量输入;
输入。推回(“1”);
输入。推回(“123”);
输入。推回(“a”);
输入。推回(“苹果”);
输入。推回(“:apple3.worm”);
std::字符串模式(“[0-9]”);
std::regex r(模式,std::regex_常量::grep);
用于(自动常数和s:输入)
{
bool ok=std::regex_匹配(s,r);
如果你仔细阅读这份文件,你会注意到:

整个目标序列必须与正则表达式匹配,此函数才能返回true(即,在匹配之前或之后没有任何附加字符)。有关匹配仅为序列一部分时返回true的函数,请参阅regex\u search

因此,如果要检查字符串是否至少包含1个数字,请将正则表达式更改为
*[0-9].*


请注意,我无法复制您的输出,我的输出是:

POS: 1
NEG: 123
NEG: a // <- here's the diff
NEG: apple
NEG: :apple3.worm
POS:1
负数:123

NEG:a//Why
[0-9]
匹配
a
?我明白你关于完全匹配的说法。我的问题是输出中的第三行。我将用g++版本更新我的帖子。你应该给我们更多关于你的
g++
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.4-2ubuntu1~14.04.3' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
POS: 1
NEG: 123
NEG: a // <- here's the diff
NEG: apple
NEG: :apple3.worm