다음과 같은 문자열이 있습니다.
Student 12:00AMLeoPan Final points
<!--<div class='icon displayOn' ><span onclick=';' title=''></span></div>-->0.5
2.00<!--<div class='icon'><spanonclick='' title=''></span></div>-->
문자열 StartWith <!--<div
를 end 로 바꾸고 </div>-->
문자열  
을 ""
값 으로 바꾸고 싶습니다 .
내 코드로 시도했습니다.
string finalResult = Regex.Replace(abc, "<!--<div" + ".*</div>--> ", "")
.Replace("<!--<div" + ".*</div>-->", "")
.Replace(" ", "");`
그러나 Regex.Replace
대체 할 수 없습니다.
이 문자열을 제거하는 방법? 감사.
업데이트 1 :
감사합니다, @Mark.
나는 시도했다 : .Replace("<!--<div" + ".*</div>-->", "")
.
그리고 모두 제거합니다.
<!--<div class='icon displayOn' ><span onclick=';' title=''></span></div>-->0.5 2.00<!--<div class='icon'><spanonclick='' title=''></span></div>-->
.
결과 만 : Student 12:00AMLeoPan Final points
.
두 개가 시작 : <!--<div
으로 끝나는 것을 볼 수 있습니다 : </div>-->
.
그러나 그것은 모두를 대체합니다. 최종 결과가 다음과 같이 표시되기를 원합니다.
Student 12:00AMLeoPan Final points 0.5 2.00
Regex.Replace
을 반환 string
하므로 두 번째 및 세 번째 Replace
호출은 실제로 String.Replace
정규식을 지원하지 않는을 호출 합니다. 호출을 연결하지 마십시오. 매번 Regex.Replace를 명시 적으로 호출하십시오.
string r1 = Regex.Replace(abc, "<!--<div.*?</div>--> ", "");
string r2 = Regex.Replace(r1, "<!--<div.*?</div>-->", "");
string finalResult = Regex.Replace(r2, " ", "");
업데이트 : @WhoIsRich가 질문에 대한 의견에서 언급했듯이 정규식이 욕심이 없도록 수정되었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다