0

I have a String input and I need to remove two digit numbers from the string, wherever it appears.

Example:

str = "abcdef12efgh abc12 abc12345defg 12 12abc abc123"

The required output should be:

abcdefefgh abc abc12345defg abc abc123

I am able to remove the two digits prefixed/suffixed by '<space>', but not 'abcdef12efgh'.

Is there a regex for doing this? Or should I iterate through the string and remove the two digit numbers checking if the string has non-numeric character before/after it.

1 Answer 1

4

This might work. (?<!\d)\d{2}(?!\d)

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

Comments

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.