I have a long Regex (JavaScript), and it contains the following construct:
((?:\\[^$&\\])|(?:[^$&\\]))*
The regex says:
Match any String, that doesn't contain the symbols $
&
and \\
The symbol \\
is allowed, if it's used for escaping. But only, if it doesn't escape one of the forbidden symbols.
Here's a simple match-example:
this
& IsAText\\nWithNewLines
$ And
\\$ Forbidden
\\\\ Symbols
I wonder if it's possible to optimise this regular expression. This is only a little example, the actual regex I'm using is bigger due to many different symbols I have to write twice.
why not just \\\\?[^$&\\\\]
? Optional \\
followed by your negate group.
It would make the whole thing (\\\\?[^$&\\\\])*
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.