Deepti Kakade
Deepti Kakade

Reputation: 3203

Find a regular expression for following string

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

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Use this regex and then replace the match with an empty string:

(?<=\.) (?=[A-Z]\b)|[.,'"]

Here is a demonstration.

Upvotes: 1

Related Questions