std::regex_replace
De cppreference.com
[] |
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. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <regex>
|
||
template< class OutputIt, class BidirIt, class Traits, class CharT, class STraits, class SAlloc > OutputIt regex_replace( OutputIt out, BidirIt first, BidirIt last, const std::basic_regex<CharT,Traits>& e, const std::basic_string<CharT,STraits,SAlloc>& fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(1) | (depuis C++11) |
template< class OutputIt, class BidirIt, class Traits, class CharT > OutputIt regex_replace( OutputIt out, BidirIt first, BidirIt last, const std::basic_regex<CharT,Traits>& e, const CharT* fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(2) | (depuis C++11) |
template< class Traits, class CharT, class STraits, class SAlloc, class FTraits, class FAlloc > std::basic_string<CharT,STraits,SAlloc> regex_replace( const std::basic_string<CharT,STraits,SAlloc>& s, const std::basic_regex<CharT,Traits>& e, const std::basic_string<CharT,FTraits,FAlloc>& fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(3) | (depuis C++11) |
template< class Traits, class CharT, class STraits, class SAlloc > std::basic_string<CharT,STraits,SAlloc> regex_replace( const std::basic_string<CharT,STraits,SAlloc>& s, const std::basic_regex<CharT,Traits>& e, const CharT* fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(4) | (depuis C++11) |
template< class Traits, class CharT, class STraits, class SAlloc > std::basic_string<CharT> regex_replace( const CharT* s, const std::basic_regex<CharT,Traits>& e, const std::basic_string<CharT,STraits,SAlloc>& fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(5) | (depuis C++11) |
template< class Traits, class CharT > std::basic_string<CharT> regex_replace( const CharT* s, const std::basic_regex<CharT,Traits>& e, const CharT* fmt, std::regex_constants::match_flag_type flags = std::regex_constants::match_default ); |
(6) | (depuis C++11) |
1)
Construit un objet std::regex_iterator
i comme par std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags), et l'utilise pour faire dfiler tous les matches de e dans le [first,last) squence. Pour chaque match de tels m, copie la sous-squence non apparie (m.prefix()) dans out comme a, et puis remplace la sous-squence correspond la chane de remplacement format comme si en appelant m.format(out, fmt, flags). En l'absence de plus de correspondances sont trouves, copie les autres non apparis caractres out .Original:
Constructs a std::regex_iterator object
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.The text has been machine-translated via Google Translate.
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.
S'il n'y a aucune correspondance, copie la squence entire en tant que
out-est .Original:
If there are no matches, copies the entire sequence into
out as-is.The text has been machine-translated via Google Translate.
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.
Si
flags contient std::regex_constants::format_no_copy, les squences non apparies sont pas copis dans out .Original:
If
flags contains std::regex_constants::format_no_copy, the non-matched subsequences are not copied into out.The text has been machine-translated via Google Translate.
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.
Si
flags contient std::regex_constants::format_first_only, seule la premire correspondance est remplac .Original:
If
flags contains std::regex_constants::format_first_only, only the first match is replaced.The text has been machine-translated via Google Translate.
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.
2)
identique 1), mais le remplacement en forme est ralise comme en appelant
m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)Original:
same as 1), but the formatted replacement is performed as if by calling
m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)The text has been machine-translated via Google Translate.
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.
3-4)
Construit une chane vide
result de std::basic_string<CharT, ST, SA> type et appelle std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags) .Original:
Constructs an empty string
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).The text has been machine-translated via Google Translate.
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.
5-6)
Construit une chane vide
result de std::basic_string<CharT> type et appelle std::regex_replace(std::back_inserter(result), s, s + std::char_traits<CharT>::length(s), e, fmt, flags) .Original:
Constructs an empty string
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).The text has been machine-translated via Google Translate.
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.
Paramtres
| first, last | - | la squence de caractres d'entre, reprsente comme une paire d'itrateurs
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 | - | la squence de caractres d'entre, reprsent comme std :: basic_string ou tableau de caractres
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 | - | le std :: basic_regex qui sera en correspondance avec la squence d'entre
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 | - | les drapeaux du match de std::regex_constants::match_flag_type 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 | - | la chane regex format de remplacement, la syntaxe exacte dpend de la valeur de
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 | - | itrateur de sortie pour stocker le rsultat du remplacement
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.
| ||
Retourne la valeur
1-2)
Renvoie une copie de l'itrateur de sortie
out .Original:
Returns a copy of the output iterator
out.The text has been machine-translated via Google Translate.
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.
3-6)
Retourne la chane de caractres qui contient
result la sortie .Original:
Returns the string
result which contains the output.The text has been machine-translated via Google Translate.
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.
Exceptions
Peut gnrer std::regex_error pour indiquer une condition d'erreur .
Original:
May throw std::regex_error to indicate an condition d'erreur.
The text has been machine-translated via Google Translate.
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.
Exemple
#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';
}
Rsultat :
Q[u][i]ck br[o]wn f[o]x
Voir aussi
(C++11) |
tente de faire correspondre une expression rgulire de toute partie de la squence de caractres 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. (fonction gnrique) |
(C++11) |
options spcifiques l'appariement 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) |