4

これらの要件を満たす正規表現を作成するにはどうすればよいですか? string.replaceAll 関数しか使用できません..

a)”段落の最後に表示されるもので“、 を含むが含まないもの —“ “削除”

b)“段落の先頭に表示されているものを削除 “ [注: がある場合は“ “、現在は である必要があります“]

c)段落の先頭に”一致せずに段落の末尾に表示されるもの–削除“”

編集:

Rule a)
Transform:
String input1 ="“remove quotes”" 
String output1 ="“remove quotes"

Don't change anything:
String input1 ="““remove quotes”" 
String output1 ="““remove quotes”"

Rule b)
Transform:
String input1 ="“remove quotes”" 
String output1 ="remove quotes”"

Replace with single ldquo:
String input1 ="““remove quotes”" 
String output1 ="“remove quotes”"

Rule c)
Do nothing (there is a matching ldquo):
String input1 ="“do not remove quotes”" 
String output1 ="“do not remove quotes”"

Transform(no matching ldquo hence remove rdquo):
String input1 ="remove quotes”" 
String output1 ="remove quotes"

I think I am going to run all the 3 rules separately on the string. What would be 3 regexes and replace expressions ? 
4

2 に答える 2

0

私がよく理解していれば、次のような文字列:

“ Criteria 1, ending with RD and beginning with LD, but not LDLD, remove RD ”
“ “ Criteria 1, ending with RD but beginning with LDLD, do nothing to RD ”
“ “ Criteria 2, beginning with LDLD, make it begin with LD ”
Criteria 3 with non-matching RD, remove RD ”

なるために:

“ Criteria 1, ending with RD and beginning with LD, but not LDLD, remove RD
“ Criteria 1, ending with RD but beginning with LDLD, do nothing to RD ”
“ Criteria 2, beginning with LDLD, make it begin with LD ”
Criteria 3 with non-matching RD, remove RD

次の正規表現を使用できます。

^(?:(“(?! “).*?)\s*”|(“) “(.*)|((?!“).*?)\s*”)$

と置き換え$1$2$3$4ます。

ここでどのように機能するかを参照してください。

または、シンボルを意味する場合は、ここで別の同様のものを見つけることができます.

“ Criteria 1, ending with RD and beginning with LD, but not LDLD, remove RD ”
“ “ Criteria 1, ending with RD but beginning with LDLD, do nothing to RD ”
“ “ Criteria 2, beginning with LDLD, make it begin with LD ”
Criteria 3 with non-matching RD, remove RD ”

なる:

“ Criteria 1, ending with RD and beginning with LD, but not LDLD, remove RD
“ Criteria 1, ending with RD but beginning with LDLD, do nothing to RD ”
“ Criteria 2, beginning with LDLD, make it begin with LD ”
Criteria 3 with non-matching RD, remove RD

そして、正規表現をより理解しやすくする可能性のある debuggex 画像が必要な場合:

正規表現イメージ

于 2013-06-14T07:45:48.950 に答える