简体   繁体   中英

Javascript regex: match any character that is not in the set of symbols (but only if this symbol doesn't follow a backslash)

I need a regex which matches any character that is not in the set of symbols (but only if this symbol doesn't follow a backslash)

Is there any one line solution?

sample input: "Test1\,test2,test3\<\>test4<>test5"
reqex to improve: /[^,<>]+/

expected output: 在此处输入图像描述

Assuming \ is not at the first position of a match you may use this regex:

[^,<>\\]+(?:\\.[^,<>\\]*)*

RegEx Details:

  • [^,<>\\]+ : Match 1 or more of any character that are not inside the the [...]
  • \\. match any escaped character

RegEx Demo

If \ can be at first position then you may use:

(?:\\.|[^,<>\\]+)+

RegEx Demo 2

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM