firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.24k stars 199 forks source link

C# generated code fails with Unrecognized escape sequence \\N. #1938

Closed PaulEPetersen closed 1 year ago

PaulEPetersen commented 1 year ago

Bug Description

When generating c# code using the \N works in the https://regex101.com/ website but putting the generated code into c# doesnt work

System.Text.RegularExpressions.RegexParseException HResult=0x80070057 Message=Invalid pattern '(?\d{2}\/\d{2}\/\d{4})\,\s(?

Reproduction steps

generate c# regex using https://regex101.com/ using \N

Expected Outcome

the regex works in C#

Browser

N/A

OS

Windows 11

working-name commented 1 year ago

Did .net recently implement N? Otherwise you may be writing your regex in PCRE expecting it to work in .net which unfortunately won't work 100%. Some features exist in either of the engines that the other doesn't have.

PaulPetersenAtTheAA commented 1 year ago

I don't know, I would guess. Net hasn't implemented hence the problem. The generator should only generate working code IMHO. Not sure what pcre is

working-name commented 1 year ago

It generates example code for a specific language you choose, but it doesn't interpret and translate regex from one flavor to another - that would be a rather huge undertaking and at times impossible because there isn't always an alternate way of doing something.

Generally if you select the target flavor (.net) while you're developing the regex you're going to get feedback on things not implemented - although it could also be the site not running the latest and greatest .net build for example. Either way, it's probably less headache than finding out like this.

Hope this helps 😃