正则表达式无法打印 [英] Regex unable to print
问题描述
我使用这个Regex语句来运行。但由于某种原因,它不在终端打印。
I am using this Regex statement to run. But for some reason it does not print in the terminal .
string s (filename);
smatch m;
regex e ("(\\.[^.]+)$");
regex_search (s,m,e);
cout << m.suffix().str() <<endl;
我做错了什么?按照教程,但由于某种原因不打印。
What did I do wrong ? Follow the tutorial but it does not print for some reason.
推荐答案
请参阅 后缀
参考:
获取对
std :: sub_match
对象的引用,表示目标序列 / strong>正则表达式和目标序列的结束。
Obtains a reference to the
std::sub_match
object representing the target sequence between the end of the entire match of the regular expression and the end of the target sequence.
是空的,因为您匹配字符串的结尾。如果您需要打印匹配值,请使用 m.str()
或 - 因为您将模式放入捕获组 - m.str 1)
。
In your case, it is empty since you matched the end of string. If you need to print the match value, use m.str()
or - since you placed the pattern into a capturing group - m.str(1)
.
请参阅 IDEONE C +演示
这篇关于正则表达式无法打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!