2017-03-12 13 views
0

パターンは常に特定のキーから始まります(例:が必要です。) 値は複数行にすることができます。 パターンは特定のキーの1つで終了できます(例:ending1またはending1)。ターミネーションキーは、入力テキストに両方または1つのみを表示できます。両方の場合、最初のものだけが必要です。この例の正規表現テンプレートの条件付き終了

私の正規表現パターンは次のようになります。ここではneeded beginning([\S\s]*)(?>ending1|ending2)

Regex101はexample

第二のキャプチャグループを動作していない、完全に間違っている、と私は

このケースを実現する方法がわかりません

some 
other 
not 
interesting 
text 
needed beginning 
value  <-- 
can be  <-- this needed to be captured 
multiline <-- 
ending1 
some other values 
and other 
ending2 
some 
other 
not 
interesting 
text 

またはこのような:入力テキストは、このようにすることができます

some 
other 
not 
interesting 
text 
needed beginning 
value  <-- 
can be  <-- this needed to be captured 
multiline <-- 
ending2 
some 
other 
not 
interesting 
text 

答えて

2

これはあなたのために機能しますか? 更新:正規表現の使用https://regex101.com/r/SBNUQG/2

を:(ending1は| ending2)から始まる必要をします、現在の論理の

+1

ほとんどの部分は、複数行の入力で動作するオプション "シングルライン" で

をして、このフラグを追加(*?。)他の部品を再確認して交換する必要があります。 'singleline'フラグを付けずにこれを行うことは可能ですか? – aleha

+0

@aleha必要な開始([\ s \ S] *?)(ending1 | ending2) 'を使用すると、' s'フラグを避けることができます。 –

+0

'*?'がポイントです。どうも。 – aleha