1

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"

1 Answer 1

1

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

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

Here is a demonstration.

Sign up to request clarification or add additional context in comments.

2 Comments

The above expression is not working if the string is like "A. B.C D., WOW K Bench" it is giving the ABC D WOW K Benchoutput. I want the output ABCD WOW K Bench
@DeeptiKakade please add some explanation to your question. What would be the expected output for the above input and why? And it's better to ask it as a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.