Reputation: 3203
I have string and that string has four formats:
str = "A. B.C. D, WOW, 'H' BENCH"
str1 = "ABCD WOW BENCH \"k\""
str2 = "A.B.C.D,. WOW 'K' BENCH"
str3 = "ABCD, WOW 'K' BENCH"
The string will come in any one of the formats, so I want the regular expression which will give me the following results respectively:
str = "ABCD WOW H BENCH"
str1 = "ABCD WOW BENCH K"
str2 = "ABCD WOW K BENCH"
str3 = "ABCD WOW K BENCH"
Upvotes: 1
Views: 50
Reputation: 174696
Use this regex and then replace the match with an empty string:
(?<=\.) (?=[A-Z]\b)|[.,'"]
Here is a demonstration.
Upvotes: 1