01210210021212333212300213231102023103130001332121230221000012333333021032112 아래 문자열에서 0123의 모든 순열을 찾고 싶습니다.
문자열에서 일치하는 0123의 순열을 제공 할 수있는 정규식을 가질 수 있습니까? 또한 겹쳐진 패턴이 있으면 필요합니다.
"0123"여기에 [1023] [1230] [2301] [3012]의 일치 항목이 있습니다.
정규식이 아니라 C ++ 11 :
#include <iostream>
#include <algorithm>
#include <string>
int main()
{
const std::string s("01210210021212333212300213231102023103130001332121230221000012333333021032112");
const std::string ref("0123");
if(ref.length() > s.length())
{
return 0;
}
for(int i = 0; i < s.length() - ref.length(); ++i)
{
if(std::is_permutation(s.cbegin()+i, s.cbegin()+i+ref.length(), ref.cbegin()))
{
const std::string extract(s, i, ref.length());
std::cout << extract << std::endl;
}
}
return 0;
}
예를 들어 컴파일하려면 g++ -std=c++11 -o sample sample.cpp
정규식이 절대적으로 필요한 경우 : (?=[0123]{3})(.)(?!\1)(.)(?!\1|\2)(.)(?!\1|\2|\3).
이는 다음 을 의미합니다.
(?=[0123]{3}) : positive assertion that the 4 next characters are 0, 1, 2, 3
(.) : capture first character
(?!\1) : assert that following character is not the first capture group
(.) : capture second character
(?!\1|\2) : assert that following character is neither the first nor the second capture group
etc.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다