そのようなテキストドキュメントがあるとしましょう
1
M1577682
Wayne United States Minnesota Minneapolis 55 2019-10-31 14:51:05
2
M1527197
henrik Denmark Sjelland Koge 52 2019-10-31 14:29:53
3
M3455913
Kim Canada Ontario London 61 2019-10-30 21:36:03
4
M2040689
shapo Germany Hesse-Darmstadt Frankfurt 45 2019-10-31 13:19:12
そのテキストから次のような行を作成する必要があります。
M1577682,M1527197,M3455913,M2040689
この^(?!。M1577682)(。?)$は、M1577682を含まないものをすべて選択することがわかりました。
そして、この\ bM \ w {7、}は、Mで始まり、その後に7文字以上の単語を選択します。(まだミネソタとミネアポリスも選択していますが、修正できません)
では、どういうわけか、これら2つの正規表現をマージして、Mで始まらず、7桁(文字)のすべてを選択し、それをコンマに置き換えることはできますか?
これが進む方法です。その後、最後のコンマを手動で削除する必要があります。
(?:(?:(?!M\d{7}).)*|\G)(M\d{7})(?:(?!M\d{7}).)*
$1,
. matches newline
説明:
(?: # non capture group
(?: # non capture group
(?! # negative lookahead, make sure we haven't after:
M # the letter M
\d{7} # 7 digits
) # end lookahead
. # any character
)* # end group, may appaear 0 or more times
| # OR
\G # restart from last match position
) # end group
( # group 1
M # the letter M
\d{7} # 7 digits
) # end group 1
(?: # non capture group
(?! # negative lookahead, make sure we haven't after:
M # the letter M
\d{7} # 7 digits
) # end lookahead
. # any character
)* # end group, may appear 0 or more times
注:それは交換するケースだ場合は、単語の境界を追加することが可能M\d{7}
で\bM\d{7}\b
どこでも正規表現インチ
スクリーンキャプチャ(前):
スクリーンキャプチャ(後):
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加