2012-02-22 2 views
1

내가 목표 - C에서이 정규 표현식을홀수 정규 표현식 결과 .../문자

NSString* searchString = [searchBlock stringByReplacingOccurrencesOfString:@"<(.*?)>" withString:@"" options: NSRegularExpressionSearch range:NSMakeRange (0, [searchBlock length])]; 

뾰족한 brackets < 사이에 오는 모든 것을 제거>하고는 대부분의 시간을 작동하는 것 같다해야하는 코드 만 이 경우에 실패 보인다 잘 모르겠어요 이유 :

<a href="http://www.twitter.com/starkpo"> 
     <img height="120" width="124" alt="Follow us @starkpo." style="border: 0;" 
     src="http://www.thestarkingtonpost.com/wp-content/uploads/2009/09/twitter-master.jpg" 
     title="Join us on Twitter" /> 
    </a> 
    <p style="font-size: 11px; line-height: 17px; margin: 0; padding: 0 4px 5px;">Follow us @starkpo.</p></div> 

반환 :

<img height="120" width="124" alt="Follow us @starkpo." style="border: 0;" 
     src="http://www.thestarkingtonpost.com/wp-content/uploads/2009/09/twitter-master.jpg" 
     title="Join us on Twitter" /> 

    Follow us @starkpo. 

예상 답변은 단순히 일반 텍스트를 반환하는 것입니다 : @starkpo를 팔로우하십시오.

자기 폐쇄 태그를 무시하는 이유는 무엇입니까?

감사합니다.

답변

1

.과 일치하는 줄 바꿈도되도록 정규식 엔진에 알려야합니다.

NSRegularExpressionDotMatchesLineSeparators-options을 더합니다.

+0

다른 사람이이 글을 읽는 경우를 대비해주의하십시오. 이 플래그는 NSString의 일부가 아닙니다. 이 작업을하려면 실제 NSRegularExpression을 만들어야합니다. – itgiawa

1

.은 기본적으로 개행과 일치하지 않습니다.

NSRegularExpressionDotMatchesLineSeparators 플래그를 사용하여 활성화 할 수 있습니다.