0

I have a requirement to identify two patterns in a String, and if exists, i need to remove the substrings. Currently my code is below where I'm removing the substrings in two steps. I want to create a single Regex to identify "A," or "S," if exists, to replace with empty string.

My code:

if (charCode === characteristicsCode.SERIAL_NUMBER) {
                charValue = charValue.replace(/[(A,)]/g, '');
                charValue = charValue.replace(/[(S,)]/g, '');
}

1 Answer 1

1

The pipe | operator works as an or in regex, so this:

charValue = charValue.replace(/[A|S]/g, '')
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.