Regex for matching string with double backlash or backlash followed by double quotes
I want to create a regex that satisfies the following condition:
- Can contain any character that is not
n
andr
. Can be empty string. - Can contain
"
and\
, but"
andare not allowed.
Positive examples: abc d
, my "time"
, D:\willy\wonka
, foo\"bar
.
Negative examples: my "laser"
, D:willibadehose
, foo\"bar
.
I tried using positive lookbehind, but abc d
is not matched and foo\"bar
is matched:
^[^rn]*(?<=\)("|\)[^rn]*$
How can I fix this? Here is the link to regex101 for ease of testing: regex101.com/r/I1byls/1
Read more here: Source link