Programming/C++

[C++] 문자열 치환 함수 regex_replace

몽땅마니아(MDD) 2021. 12. 30. 22:09

참고 블로그 ( replace 와 regex_replace 모두 깔끔하게 정리 잘 해놓으셨다👍👍 )

https://ponyozzang.tistory.com/678

 

C++ 문자열 치환 replace, regex_replace 사용 방법 예제

C++에서 문자열을 치환하는 방법을 알아보도록 하겠습니다. 문자열을 치환해주는 함수로 replace와 regex_replace가 있습니다. 대상 문자열에서 지정한 위치부터 원하는 문자로 바꿔줍니다. 또는 대상

ponyozzang.tistory.com

regex_replace( 대상 문자열, regax(바꿀 문자열), 치환할 문자열)
  • #include <regex> 필요 (regex == regular expression)
#include <iostream>
#include <regex>
#include <string>

using namespace std;
int main() {

	string s = "abcabca";
	string s1 = regex_replace(s, regex("ab"), "12");
	cout << s1<< endl;
	//결과 : 12c12ca
	return 0;
}

'Programming > C++' 카테고리의 다른 글

[C++] STL 문자열(string) 사용법  (0) 2021.12.24
[C++] STL 맵(map) 사용법  (0) 2021.10.23
C++ STL 페어(pair) 사용법  (0) 2021.10.22
C++ STL 벡터(vector) 사용법  (0) 2021.10.22
C++ STL 덱(deque) 사용법  (0) 2021.10.22