How do I write a regular expression to satisfy these requirements ? I can only use a string.replaceAll function ..
a) For ” which appears at end of paragraph which has a “, but not “ “—remove ”
b) For “ which appears at beginning of paragraph remove “ [NOTE: If there is “ “, it should now be “]
c) For ” which appears at end of paragraph without a matching “ at beginning of paragraph –remove ”
EDIT:
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 ?
This regex will do the following:
“ strings and a ending ”, then remove single “
“ string and a ending ”, then remove nothing“ strings and a ending ”, then remove ending ”
regex: ^(?=.*?”)“\s*(“)|^(?=.*?”)(“.*?”)|^(?!“)(.*?)”
replace with: $1$2$3

Input text
“ DO NOTHING ”
“ “ REMOVE INITIAL LD ”
REMOVE RD ”
Output text respecitivly
“ DO NOTHING ”
“ REMOVE INITIAL LD ”
REMOVE RD
These expressions where hashed out from a chat session, and written to be executed one at a time in A,B,C order, however because they are seperate, they can be executed in any order the developer would like which would change based on the desired output.
A
^(“(?!\s*“).*?)” $1 B
^“(\s*(?:“)?) $1 C
^(?!“)(.*?)” $1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With