std::regex_match
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <regex> 中定义
|
||
template< class BidirIt, class Alloc, class CharT, class Traits > |
(1) | (C++11 起) |
template< class BidirIt, class CharT, class Traits > |
(2) | (C++11 起) |
template< class CharT, class Alloc, class Traits > bool regex_match( const CharT* str, |
(3) | (C++11 起) |
template< class STraits, class SAlloc, class Alloc, class CharT, class Traits > |
(4) | (C++11 起) |
template< class CharT, class Traits > bool regex_match( const CharT* str, |
(5) | (C++11 起) |
template< class STraits, class SAlloc, class CharT, class Traits > |
(6) | (C++11 起) |
e
,同时考虑到的效果[first,last)
flags
和整个目标字符序列。比赛结果中返回m
.e
and the entire target character sequence [first,last)
, taking into account the effect of flags
. Match results are returned in m
.目录 |
[编辑] 参数
first, last | - | 目标应用正则表达式的字符范围,作为迭代器
原文: the target character range to apply the regex to, given as iterators |
m | - | 比赛结果
|
str | - | 在目标字符串,给出一个空结束的C风格字符串
原文: the target string, given as a null-terminated C-style string |
s | - | 在目标字符串,作为一个std::basic_string
原文: the target string, given as a std::basic_string |
e | - | 正则表达式
|
flags | - | 使用的标志,以确定比赛将如何进行
原文: flags used to determine how the match will be performed |
类型要求 | ||
-BidirIt 必须满足 BidirectionalIterator 的要求。
|
[编辑] 返回值
m
,如下:m
is updated, as follows:m.ready() == true | |
m.empty() == true | |
m.size() == 0 |
m.ready() | true |
m.empty() | false |
m.size() | 的子表达式数加1,即,1+e.mark_count()
原文: number of subexpressions plus 1, that is, 1+e.mark_count() |
m.prefix().first | first
|
m.prefix().second | first
|
m.prefix().matched | false(匹配前缀为空)
|
m.suffix().first | last
|
m.suffix().second | last
|
m.suffix().matched | false(匹配后缀是空的)
|
m[0].first | first
|
m[0].second | last
|
m[0].matched | true(整个序列的匹配)
原文: true (the entire sequence is matched) |
m[n].first | 的序列,如果该子表达式匹配的子表达式n,或
last 没有参加比赛的开始原文: the start of the sequence that matched sub-expression n, or last if the subexpression did not participate in the match |
m[n].second | 的序列,如果该子表达式匹配的子表达式n,或
last 没有参加比赛的结束原文: the end of the sequence that matched sub-expression n, or last if the subexpression did not participate in the match |
m[n].matched | true如果子的表达式n参加的比赛中,false其他方式
原文: true if sub-expression n participated in the match, false otherwise |
[编辑] 示例
#include <iostream> #include <string> #include <regex> int main() { std::string fnames[] = {"foo.txt", "bar.txt", "zoidberg"}; std::regex txt_regex("[a-z]+\\.txt"); for (const auto &fname : fnames) { std::cout << fname << ": " << std::regex_match(fname, txt_regex) << '\n'; } }
输出:
foo.txt: 1 bar.txt: 1 zoidberg: 0
[编辑] 另请参阅
(C++11) |
正则表达式对象 (类模板) |
(C++11) |
确定一个正则表达式匹配,包括所有的子表达式匹配 原文: identifies one regular expression match, including all sub-expression matches (类模板) |