๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/Note

[C++, ์œ ์šฉํ•œ ๋ฌธ๋ฒ•] ํŠน์ •๋ฌธ์ž ์น˜ํ™˜ regex_replace

by dkswnkk 2022. 4. 9.

ํŠน์ •๋ฌธ์ž ๋ณ€ํ™˜ regex_replace

#include <iostream>
#include <regex>

using namespace std;

int main(){
    string s = "OneTwoThree";
    string s2 = "...";
    
    //regex_replace (๋Œ€์ƒ, ์ •๊ทœํ‘œํ˜„์‹ ๊ฐ์ฒด, ์น˜ํ™˜ ๊ฒฐ๊ณผ)
    s = regex_replace(s, regex("One"), "1");
    s = regex_replace(s, regex("Two"), "2");
    s = regex_replace(s, regex("Three"), "3");
    s2 = regex_replace(s2, regex("[.]{2,}"), ".");
    // s = "123", s2 = "."
}

 

์ •๊ทœ ํ‘œํ˜„์‹

๋Œ“๊ธ€