You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
franckleveque:
It seems that since C# 11 (.net 7) a new way is using """ at the beginning
and the end of a string to allow brut string without any escaping sequence
interpretation but it is not preceded by @. However I never used it. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/
Incidental find while discussing another aspect of .NET behavior.
using System;using System.Text.RegularExpressions;publicclassExample{publicstaticvoidMain(){stringpattern=@"""""\w+""""";stringinput=@"this is a ""test""";RegexOptionsoptions= RegexOptions.Multiline;foreach(Match m in Regex.Matches(input, pattern, options)){
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);}}}
We should utilize """ raw string literals instead, which would make the code above output as expected:
stringpattern= """
"\w+"
""";
NOTE: the code generator will likely have to count the number of consecutive " characters inside the user's regex pattern, and simply enclose the whole shabang in +1 " characters, i.e.
stringinput= """""I like apples, """",and oranges.""""";
The text was updated successfully, but these errors were encountered:
Incidental find while discussing another aspect of .NET behavior.
This regex does not produce working code:
We should utilize
"""
raw string literals instead, which would make the code above output as expected:NOTE: the code generator will likely have to count the number of consecutive
"
characters inside the user's regex pattern, and simply enclose the whole shabang in +1"
characters, i.e.The text was updated successfully, but these errors were encountered: