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, '');
}
The pipe |
operator works as an or
in regex, so this:
charValue = charValue.replace(/[A|S]/g, '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.