-2

正規表現を使用して、以下のテキストのブロックだけですべての文字を削除するにはどうすればよいですか\r\n(1 行に変換するため) 。<out>...</out>

<nx1>home</nx1>
<nx2>living</nx2>
<out>text one
text continues
and at last!</out>
<m2>dog</m2>

このテキスト サンプルの最終結果は次のようになります。

<nx1>home</nx1>
<nx2>living</nx2>
<out>text one text continues and at last!</out>
<m2>dog</m2>
4

1 に答える 1

4

検索する

(?<=<out>(?:(?!</?out>).)*)\r\n(?=(?:(?!</?out>).)*</out>)

すべてを単一のスペースに置き換えます。EditPad Pro 7.3.1 でテスト済み。ドットが改行にも一致するように、必ず「ドット」オプションを選択してください。

説明:

(?<=               # Look behind to assert that there is...
 <out>             # an <out> tag before the current position,
 (?:(?!</?out>).)* # followed by anything except <out> or </out> tags
)                  # End of lookbehind
\r\n               # Match \r\n
(?=                # Look ahead to assert that there is...
 (?:(?!</?out>).)* # any number of characters ahead (except <out>/</out> tags)
 </out>            # followed by an </out> tag
)                  # End of lookahead
于 2014-05-27T11:06:33.330 に答える