2017-09-26 9 views
1

私はREGEX検索を使ってわずかに変更しようとしているcsvの値のリストを持っており、Notepad ++を使って置き換えています。私は、以下の例が含まれているもの:私がやりたいと思ってる何Regex notepadの間の置換++

Text,UK_BT.BT1.BT1 1,123 
Text,UK_BT.BT11.BT11 1,123 
Text,IE_text.text.text,123 

を、唯一ラインがUK_BTが含まれている場合は、最初のカンマと最後の期間の間のテキストを削除です。したがって、出力は次のようになります。

Text,BT1 1,123 
Text,BT11 1,123 
Text,IE_text.text.text,123 

誰か手がかりがありますか?正規表現は本当に私の強みではなく、一般にそれを使用した後に忘れ去られます! おかげで、

+1

なぜ 'Text、IE_text.text、123'が' Text、IE_text.text.text、123'になるのですか? – polkduran

+0

Typo、修正されました:) –

答えて

3

は何を探す:

^(?=.*UK_BT.*)([^,]+,).*\.([^\.]+)$\1\2

説明

^    # Beginning of the line. 
(?=.*UK_BT.*) # Must contain 'UK_BT' (positive look ahead, not capturing group, not character consuming). 
(   # Beginning of the first group. 
    [^,]+,  # Everything but ',' at least one time (+) followed by ',' (first ','). 
)    # End of the first group. 
.*   # Everything zero or more times. 
\.   # A single '.'. 
(   # Beginning of the second group. 
[^\.]+  # Everything but '.' at least one time (this in combination with '\.' allows to find the last '.'). 
)    # End of the second group. 
$    # End of the line 

\1\2と交換は、第一および第二のキャプチャグループを指すことができます。