나는 다음과 같은 문자열에 <b>c++</b>
로 c++
을 대체하기 위해 노력하고있어 :정규식 중첩 된 정량 +
string cssOld = Regex.Replace(
"Select the projects entry and then select VC++ directories. Select show",
"c++", "<b>${0}</b>", RegexOptions.IgnoreCase);
:
"Select the projects entry and then select VC++ directories. Select show"
내가 원하는 것이
"Select the projects entry and then select V<b>C++</b> directories. Select show"
임은이 코드를 사용하여 수
다음 오류가 발생합니다.
System.ArgumentException: parsing "c++" - Nested quantifier +.
이 코드는 다른 텍스트 (! C++)와 잘 작동합니다. + 연산자가 Regex 라이브러리가 예외를 발생시키는 것처럼 보입니다.
감사합니다. 나는 오직 + 연산자를 수용해야만 하는가 아니면이 예외를 발생시킬 수있는 다른 연산자 (*, &, \ etc)가 있습니까? –
다른 특수 문자 (http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in- regular-expressions)를 확인할 수 있습니다. 그 중 다음과 같습니다 : (\, *, +,?, |, {, [, (,), ^, $,., # 및 공백] – ionden
오 감사합니다. Regex.Escape도 잘 해냈습니다. 그래서 내 코드를 변경했습니다 : string cssOld = Regex.Replace (Regex.Escape ("프로젝트 항목을 선택한 다음 VC++ 디렉토리를 선택하고 선택"), Regex.Escape ("C++"), "$ { 0} ", RegexOptions.IgnoreCase); 그리고 제대로 작동합니다. 다들 감사 해요. –