You are on page 1of 1

out_iter regex_replace(out_iter, first_iter, last_iter, const& regex,

const& format_str, [flags])


out_str regex_replace(const& input, const& regex, const& format_str,
[flags])
Replace substrings matching the regex according to the formatting string
Regex flags affecting regex_replace
format_no_copy Don't output the parts of the input string before and after the match
format_first_only Only replace the first occurrence of the found pattern
Format specifiers
$0 or $& The string matching the whole regex
$n The string matching the n-th capture group, where n >=
$` The part of the source string that comes before the substring in $0
$' The part of the source string that comes after the substring in $0
!i"en the regex (c+)(d+)ef and the input abccddefgg, the format specifiers
will denote the following#
Repetition
Symbol Repeats matced
! $=
" >= %
+ >=
#n$ n
#n%$ >= n
#n% m$ >= n && $= m
Sets
Symbol &atces
'abc( 'ny of the characters included
')abc( 'ny of the characters (OT included
'a*+( 'ny characters in the range
'a*+,*-( 'ny characters in the ranges
'.c.( )*ui"alence class for the character
'/ae/( +pecified collating element
Classes
alpa ,owercase and uppercase letters
digit or d Digits- shorthand# \d
aln0m or 1 .haracters from either alpha or digit classes
shorthand for [_[:alnum:]]# \w
space or s /hitespace characters- shorthand# \s
blan2 +pace or tab
cntrl 0ile format escape characters 1\n, \r etc23
p0nct 4unctuation characters
lo1er ,owercase letters
0pper 5ppercase letters
grap .haracters from lower, upper, digit or punct
print .haracters from either graph or space
xdigit 6exadecimal digits 1including both lowercase and uppercase a-f3
/ 7atch any character
) 7atch beginning of input
$ 7atch end of input
3b 7atch word boundary
34 7atch anything other
than a word boundary
5 Or operator
Capture groups
Denoted with parentheses
Referred to as 36, 37 etc2
.ounted in order of left parentheses#
bool regex_match (first_iter, last_iter, match_res&, const& regex, [flags])
(first_iter, last_iter, const& regex, [flags])
(str, match_res&, const& regex, [flags])
(str, const& regex, [flags])
Returns true if the whole input string matches the regex-
details of the matches in match_res
bool regex_search
Returns true if a substring of the input string matches the regex-
+ame parameters as regex_match
Regex constr0ctor flags affecting regex_match & regex_search
matc_not_bol Don't treat the first position in the input as the beginning of line
matc_not_eol Don't treat the past-the-end position in the input as the end of a line
matc_not_bo1 Don't treat the first position in the input as the beginning of a word
matc_not_eo1 Don't treat the past-the-end position in the input as the end of a word
matc_any 'ny match is acceptable when more than one match is possible
matc_not_n0ll Don't match an empty input
matc_contin0o0s Don't search for matches other than at the beginning of the input
matc_pre8_a8ail --first is a "alid iterator- if set, ignore match_not_bol and
match_not_bow
basic_regex<CharT, Traits>(const& regex_str, [flags])
(first_iter, last_iter, [flags])
(const* regex_str, [flags])
+tores a regular expression
9onstr0ctor flags
icase 4erform case-insensiti"e matching
nos0bs Don't store sub-matches in the match_results ob8ect
optimi+e 4ay more attention to matching speed instead of the
speed of constructing a regex ob8ect2 .onstructing
a regex ob8ect with this flag can be much slower2 5se
only when you really need to speed up the matching
collate 7a9e character ranges locale sensiti"e
&etods
operator.:assign 'ssign a different regular expression
flags Return a copy of flags passed to the ctor
getloc !et the locale
imb0e +et the locale
mar2_co0nt Return the number of mar9ed sub-expressions
s1ap +wap with another regex ob8ect
:ypedefs
regex basic;regex$char>
1regex basic;regex$wchar;t>
match_results<i!irectional"ter, #lloc>
6olds the results of a regex match
&etods
operator. 'ssign another match results ob8ect
get_allocator Return the allocator
ready Return true if result state is fully established
empty Return true if size() == %
si+e Return < the number of mar9ed sub-expressions
max_si+e The max possible number of sub;match elements
format 4roduce an output se*uence using a format string
s1ap +wap with another match;results ob8ect
lengt The length of a gi"en submatch
position Distance from start of input to gi"en submatch
str .on"ert specified submatch to string type
operator'( Return a reference to the gi"en sub;match ob8ect
prefix ' reference to the sub;match ob8ect representing
the substrsing of the input before the match
s0ffix ' reference to the sub;match ob8ect for
the rest of the input after the match
begin:cbegin +tart iterator that enumerates submatches
end:cend )nd iterator that enumerates submatches
:ypedefs
smatc match;results$string##const;iterator>
1smatc match;results$wstring##const;iterator>
cmatc match;results$const char=>
1cmatc match;results$const wchar;t=>
regex_iterator
5ses regex_search to iterate o"er regex matches in the input string
:ypedefs
sregex_iterator regex;iterator$string##const;iterator>
1sregex_iterator regex;iterator$wstring##const;iterator>
cregex_iterator regex;iterator$const char=>
1cregex_iterator regex;iterator$const wchar;t=>
regex_token_iterator
>terates o"er matches or submatches in the input string
:ypedefs
sregex_to2en_iterator, 1sregex_to2en_iterator,
cregex_to2en_iterator and 1cregex_to2en_iterator defined
similarly to the typedefs for regex_iterator
sub_match<i!irectional"ter>
+tores a se*uence of characters matched by a capture group
;ata members
first >terator pointing to the start of the submatch
second >terator pointing to the end of the submatch
matced True if the ob8ect describes a submatch
&etods
lengt ,ength of the submatch string
str: .on"ert to string type
operator str_type
compare .ompare matched subse*uence
:ypedefs
cs0b_matc sub;match$const char=>
1cs0b_matc sub;match$const wchar;t=>
ss0b_matc sub;match$std##string##const;iterator>
1ss0b_matc sub;match$std##wstring##const;iterator>
C++11 ECMAScript regex
((\d+)-\2):\1
S
y
n
t
a
x
A
l
g
o
r
i
t
h
m
s
C
l
a
s
s
e
s
C
l
a
s
s
e
s
I
t
e
r
a
t
o
r
s
a b c c d d e f g g
$` $0 $` $'
$6 $7
cpprocks.com

You might also like