firasdib / Regex101

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

Double quotes can never be made valid in the c# dialect #1968

Closed Meai closed 1 year ago

Meai commented 1 year ago

Bug Description

There is no way to use double quotes without errors, even though the syntax is definitely valid and it also works in other languages. e.g \"hello\" or \"hello\"

Browser

Chrome

working-name commented 1 year ago

Hello!

I don't .net, sorry for my ignorance, but this is what I found: @-strings use "" instead of \" for quotes. @"""(.*?)"""

working-name commented 1 year ago

@Meai was this useful? Did you get it working?

Meai commented 1 year ago

@working-name sorry, it's not about how to use a Regex in c#. In c# it works fine, the problem is that the website doesn't let me use double quotes the way that c# would allow. As you can see, it doesn't matter whether I escape, double escape or not escape. The web ui refuses to work with double quotes no matter what: image

working-name commented 1 year ago

@Meai I understand that you would like the UI to accept escapes, but that may be applicable to strings other than @-strings which are a C# thing as far as I understand. Note the UI prepends @" and appends " - those are the delimiters of the string/regex which dictates you should use @-string conventions.

Can you test a little C# demo with a @-string and see if it accepts \" as an escape method?

working-name commented 1 year ago

Also, please see #1884 and #1842 for further discussion on why the @-string/raw path was chosen.

Meai commented 1 year ago

ahhh I see, I guess I didn't know how @"" works after all. I was so sure, sorry. I think it would be better to somehow use the raw equivalent, even for " doublequotes so there is only one needed. I think the new raw string literals feel the most natural, although they somehow managed to once again make it slightly confusing because you need to have the same indent level and then it doesn't add whitespace/tabs.

https://dotnetfiddle.net/x0XGbo

but this feels far easier because you can genuinely use any character. To show you, I even added more double quotes so that even three consecutive double quotes wouldn't be an issue. To be ultra safe you could use 10 or 15 so nobody will ever run into a problem again. Thank you for responding to me despite getting the @"" strings wrong, @working-name

working-name commented 1 year ago

Awesome. No need to apologize, you're talking to someone who doesn't even code in C# so ... high likelihood that I have no clue what I'm talking about. 😬