2011-11-08 23 views
1

アポストロフィを一致させる:http://pastebin.com/PZYSv1i3正規表現は、私は、次のファイルを持っている

このファイル内のすべての行は、区切り文字としてapotropheで終わります。私は、IMD + F ++ :::とseperator( ')の間のすべてのアポストロフィに一致するRegExが必要です。

私は、IMD + F ++ :::と次のセパレータの間のすべてのテキストに一致する以下のRegExを持っていますが、余分なアポストロフィだけを取り出すRegExが必要です。 .NETで

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

? –

+0

アポストロフィを置き換えたいですか?フェッチすることによってあなたは何を意味しますか? – FailedDev

+0

私がこれを好きに使うつもりのソフトウェアのregexの味がわかりません。 置換は少し不正確でした。私は、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

ありがとう、これは私がそれが欲しかったように働いた! –

関連する問題