std::regex_replace
![]() |
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 OutputIt, class BidirIt, class Traits, class CharT, |
(1) | (C++11 起) |
template< class OutputIt, class BidirIt, class Traits, class CharT > |
(2) | (C++11 起) |
template< class Traits, class CharT, class STraits, class SAlloc, |
(3) | (C++11 起) |
template< class Traits, class CharT, class STraits, class SAlloc > |
(4) | (C++11 起) |
template< class Traits, class CharT, class STraits, class SAlloc > |
(5) | (C++11 起) |
template< class Traits, class CharT > std::basic_string<CharT> |
(6) | (C++11 起) |
i
仿佛std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags)的对象,并使用它通过序列e
在每场比赛的[first,last)
步骤。对于每一次这样的比赛m
,不匹配的序列(m.prefix()
)复制到out
是替换字符串的格式化,然后替换匹配的序列,如果通过调用m.format(out, fmt, flags)。如果没有找到匹配项,其余的非匹配的字符复制到out
.i
as if by std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags), and uses it to step through every match of e
within the sequence [first,last)
. For each such match m
, copies the non-matched subsequence (m.prefix()
) into out
as-is and then replaces the matched subsequence with the formatted replacement string as if by calling m.format(out, fmt, flags). When no more matches are found, copies the remaining non-matched characters to out
.You can help to correct and verify the translation. Click here for instructions.
out
是的out
as-is.You can help to correct and verify the translation. Click here for instructions.
flags
包含std::regex_constants::format_no_copy,不会被复制到不匹配的子序列out
.flags
contains std::regex_constants::format_no_copy, the non-matched subsequences are not copied into out
.You can help to correct and verify the translation. Click here for instructions.
flags
包含std::regex_constants::format_first_only,只有第一场比赛被替换.flags
contains std::regex_constants::format_first_only, only the first match is replaced.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.
result
类型std::basic_string<CharT, ST, SA>构造一个空字符串,并调用std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags).result
of type std::basic_string<CharT, ST, SA> and calls std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags).You can help to correct and verify the translation. Click here for instructions.
result
类型std::basic_string<CharT>构造一个空字符串,并调用std::regex_replace(std::back_inserter(result), s, s + std::char_traits<CharT>::length(s), e, fmt, flags).result
of type std::basic_string<CharT> and calls std::regex_replace(std::back_inserter(result), s, s + std::char_traits<CharT>::length(s), e, fmt, flags).You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
first, last | - | 输入字符序列,表示为一对迭代器
Original: the input character sequence, represented as a pair of iterators 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 input character sequence, represented as std::basic_string or character array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
e | - | 的std ::的basic_regex,将输入序列进行匹配
Original: the std::basic_regex that will be matched against the input sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
flags | - | 匹配标志的类型std::regex_constants::match_flag_type
Original: the match flags of type std::regex_constants::match_flag_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
fmt | - | 正则表达式替换格式字符串,确切语法取决于
flags 的价值 Original: the regex replacement format string, exact syntax depends on the value of flags The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
out | - | 输出迭代器来存储结果的更换
Original: output iterator to store the result of the replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-OutputIt must meet the requirements of OutputIterator .
| ||
-BidirIt must meet the requirements of BidirectionalIterator .
|
[编辑] 返回值
out
.out
.You can help to correct and verify the translation. Click here for instructions.
result
包含输出.result
which contains the output.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.
[编辑] 为例
#include <iostream> #include <regex> #include <string> int main() { std::string text = "Quick brown fox"; std::regex vowel_re("a|o|e|u|i"); std::cout << std::regex_replace(text, vowel_re, "[$&]") << '\n'; }
Output:
Q[u][i]ck br[o]wn f[o]x
[编辑] 另请参阅
(C++11) |
尝试匹配正则表达式的字符序列的任何部分 Original: attempts to match a regular expression to any part of the character sequence 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: options specific to matching The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (的typedef) |