std::regex_match
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Defined in header <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
.You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
first, last | - | 目标应用正则表达式的字符范围,作为迭代器
Original: the target character range to apply the regex to, given as iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m | - | 比赛结果
Original: the match results The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
str | - | 在目标字符串,给出一个空结束的C风格字符串
Original: the target string, given as a null-terminated C-style string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
s | - | 在目标字符串,作为一个std::basic_string
Original: the target string, given as a std::basic_string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
e | - | 正则表达式
Original: the regular expression The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
flags | - | 使用的标志,以确定比赛将如何进行
Original: flags used to determine how the match will be performed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-BidirIt must meet the requirements of BidirectionalIterator .
|
[编辑] 返回值
m
,如下:m
is updated, as follows:You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
m.ready() == true | |
m.empty() == true | |
m.size() == 0 |
You can help to correct and verify the translation. Click here for instructions.
m.ready() | true |
m.empty() | false |
m.size() | 的子表达式数加1,即,1+e.mark_count()
Original: number of subexpressions plus 1, that is, 1+e.mark_count() The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m.prefix().first | first
|
m.prefix().second | first
|
m.prefix().matched | false(匹配前缀为空)
Original: false (the match prefix is empty) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m.suffix().first | last
|
m.suffix().second | last
|
m.suffix().matched | false(匹配后缀是空的)
Original: false (the match suffix is empty) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m[0].first | first
|
m[0].second | last
|
m[0].matched | true(整个序列的匹配)
Original: true (the entire sequence is matched) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m[n].first | 的序列,如果该子表达式匹配的子表达式n,或
last 没有参加比赛的开始Original: the start of the sequence that matched sub-expression n, or last if the subexpression did not participate in the matchThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m[n].second | 的序列,如果该子表达式匹配的子表达式n,或
last 没有参加比赛的结束Original: the end of the sequence that matched sub-expression n, or last if the subexpression did not participate in the matchThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
m[n].matched | true如果子的表达式n参加的比赛中,false其他方式
Original: true if sub-expression n participated in the match, false otherwise The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 为例
#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'; } }
Output:
foo.txt: 1 bar.txt: 1 zoidberg: 0
[编辑] 另请参阅
(C++11) |
正则表达式对象 Original: regular expression object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
(C++11) |
确定一个正则表达式匹配,包括所有的子表达式匹配 Original: identifies one regular expression match, including all sub-expression matches The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |