I wish to find a character such as ',' in a string unless it is surrounded by double quotes.
For example in the string: 'Example, "String,"'
I would like it to match the comma after 'Example' but not after 'String'.
Is there a regex that can do this?
You can negate a group of characters in regex by using (?![text])
.
For example, something like (?!"),(?!")
would find all the ,
that are not "touched" by "
. You may need to check your string with multiple variations of this regex to get the desired result but I think you should be able to work wit the given example.
Something like this?
console.log( `For example in the string: 'Example, "String,"'`.match(/, /g).length, `For example, in the following string: 'Example, "String," I'd like to find all ","'`.match(/, /g).length, )
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.