std::regex_replace – cppreference.com
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>
| definiert in Header <regex> |
||
|
|
(1) | (seit C++11) |
|
|
(2) | (seit C++11) |
|
|
(3) | (seit C++11) |
|
|
(4) | (seit C++11) |
|
|
(5) | (seit C++11) |
|
|
(6) | (seit C++11) |
1)
Erzeugt ein std::regex_iterator Objekt i wie von std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags), und nutzt sie, um durch jedes Spiel des e innerhalb der Sequenz [first,last) fort. Für jeden solchen Spiel m, kopiert den nicht angepassten Teilfolge (m.prefix()) in out wie er ist und ersetzt dann den übereinstimmenden Teilfolge mit der formatierten Ersetzungsstring, als ob durch den Aufruf m.format(out, fmt, flags). Wenn keine weiteren Übereinstimmungen gefunden werden, kopiert die verbleibenden nicht-passenden Zeichen 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.
Wenn es keine Übereinstimmungen gibt, wird die gesamte Sequenz in out wie er ist .
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.
Wenn flags enthält std::regex_constants::format_no_copy, werden die nicht-passenden Teilfolgen nicht in out kopiert .
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.
Wenn flags std::regex_constants::format_first_only enthält, wird nur die erste Übereinstimmung ersetzt .
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.
2)
Gleiche wie 1), aber der formatierten Ersatz wird wie durch Aufrufen m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags) durchgeführt
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.
3-4)
Erzeugt einen leeren String result vom Typ std::basic_string<CharT, ST, SA> und ruft 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.
5-6)
Erzeugt einen leeren String result vom Typ std::basic_string<CharT> und ruft 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.
Parameter
| first, last | - | das Eingangszeichen Sequenz, als ein Paar von Iteratoren dargestellt Original: the input character sequence, represented as a pair of iterators The text has been machine-translated via Google Translate. |
| s | - | das eingegebene Zeichen-Sequenz, wie std :: basic_string oder Zeichenarray vertreten Original: the input character sequence, represented as std::basic_string or character array The text has been machine-translated via Google Translate. |
| e | - | die std :: basic_regex, die gegen die Eingabesequenz abgestimmt werden Original: the std::basic_regex that will be matched against the input sequence The text has been machine-translated via Google Translate. |
| flags | - | die Match-Flags des Typs 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. |
| fmt | - | die regex Ersatz Format-String, hängt genaue Syntax auf den Wert der Original: the regex replacement format string, exact syntax depends on the value of The text has been machine-translated via Google Translate. |
| out | - | Ausgabeiterator um das Ergebnis der Ersetzung speichern Original: output iterator to store the result of the replacement The text has been machine-translated via Google Translate. |
| Type requirements | ||
-OutputIt must meet the requirements of OutputIterator.
| ||
-BidirIt must meet the requirements of BidirectionalIterator.
| ||
Rückgabewert
1-2)
Gibt eine Kopie des Ausgabeiterator 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.
3-6)
Gibt die Zeichenfolge result die Ausgabe enthält .
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.
Ausnahmen
Kann std::regex_error werfen, um eine Fehler geben .
Original:
May throw std::regex_error to indicate an Fehler.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#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:
Siehe auch
Versuche, einen regulären Ausdruck zu jedem Teil der Zeichenfolge entsprechen Original: attempts to match a regular expression to any part of the character sequence The text has been machine-translated via Google Translate. (Funktions-Template) [edit] | |
spezifische Optionen, um passende Original: options specific to matching The text has been machine-translated via Google Translate. (typedef) [edit] | |