2011-11-08 5 views
1

아포스트로피에 맞게 : http://pastebin.com/PZYSv1i3정규식 내가 다음 파일을 가지고

이 파일의 모든 라인은 구분자로 apotrophe로 끝납니다. 저는 IMD + F ++ :::와 seperator (') 사이의 모든 아포스트로피와 일치하는 RegEx가 필요합니다.

나는 IMD + F ++ :::와 다음 seperator 사이의 모든 텍스트를 일치시키기 위해 RegEx를 얻었지만 과도한 아포스트로피 만 가져 오는 RegEx가 필요합니다. .NET에서

(?<=IMD\+F\+\+:::)(.*?)(?='\n) 
+0

어떤 정규식 맛 (즉, 어떤 언어)에서? –

+0

아포스트로피를 바꾸시겠습니까? 가져 오는 것은 무엇을 의미합니까? – FailedDev

+0

내가 이것을 좋아할 때 사용할 소프트웨어의 정규 표현식의 맛이 확실하지 않습니다. 바꾸기가 약간 정확하지 않았습니다. IMD + F ++ :::과 마지막 사이의 아포스트로피와 일치해야합니다. ' –

답변

0

아래 정규식 :

(?<=IMD\+F\+\+:::.*)'(?!\r?\n) 

은 당신이 원하는 "추가"아포스트로피와 일치합니다.

Regex regexObj = new Regex(@"(?<=IMD\+F\+\+:::.*)'(?!\r\n)"); 
    Match matchResults = regexObj.Match(subjectString); 
    while (matchResults.Success) { 
     // matched text: matchResults.Value 
     // match start: matchResults.Index 
     // match length: matchResults.Length 
     matchResults = matchResults.NextMatch(); 
    } 

설명 :

" 
(?<=  # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) 
    IMD  # Match the characters “IMD” literally 
    \+  # Match the character “+” literally 
    F   # Match the character “F” literally 
    \+  # Match the character “+” literally 
    \+  # Match the character “+” literally 
    :::  # Match the characters “:::” literally 
    .   # Match any single character that is not a line break character 
     *   # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
) 
'   # Match the character “'” literally 
(?!  # Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    \r  # Match a carriage return character 
     ?   # Between zero and one times, as many times as possible, giving back as needed (greedy) 
    \n  # Match a line feed character 
) 
" 
+0

고마워요, 제가 원했던대로 작동했습니다! –

관련 문제