Gautzilla
❔ Match literal escape strings with a regex
Hi everyone,
I'm trying to write a simple regex so that each literal escape hexadecimal character notation is matched.
For example, in the string "hey there \x68" , i'm interested in matching "\x68", and not the unescaped "h" character.
I wrote the following Regex: "\x[0-9a-f]{2}", but it seems that the Regex.Matches method still looks at it like I'm trying to match characters using an escaped notation, as I have the following error: " Invalid pattern '\x[0-9a-f]{2}' at offset 3. Insufficient hexadecimal digits."
Does anyone know how I can specify that I want the literal strings of the form "\xnn" to be matched, rather than the corresponding unescaped characters?
Thanks!
21 replies