Exclude double-backslash substring from string

I am trying to define a string that does not allow a double backslash.

“This is a valid string”
“This is an \ invalid string”

I am trying to define it this way:

String {$[^(?!.*\\)$]}

I get the following error: “Overlapping character range”

I believe it’s because the first backslash overlaps with the second backslash.

Is there any good way to do this?

I don’t understand what that String rule is trying to match. $[] syntax defines a character set, which matches a single character. As such, putting the same character in it two times makes no sense. You seem to be trying to write an entire regexp in there, which is not what this syntax is for.

Ah okay thank you. Is there a way to exclude a substring from a string like I want to do in my example?

That’s possible, but awkward. What should a string with \\ be parsed as instead?

String { '"' stringRest }
stringRest { '"' | ![\\"] stringRest | '\\"' | "\\" ![\\"] stringRest }
1 Like