firasdib / Regex101

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

C# delimiters for 3x, 4x and 5x double quotes are not string literals #2192

Closed OnlineCop closed 9 months ago

OnlineCop commented 9 months ago

Bug Description

The default C# delimiter is @"..." (single quote string literal). The additional options currently show """...""", """"...."""", """""...""""" (3x, 4x, and 5x quote strings, but not string literals) when switching to them.

These other delimiter options should probably also be string literals.

Examples

  1. @"..." delimiter:

    • REGULAR EXPRESSION: @""((?>[^""]+|[""]{2})*)""
    • TEST STRING: @"" @"text" @"a\nb" @"a""b" @"a\""\""b"
    • SUBSTITUTION: "$1"
    • Code Generator snippet:
          public static void Main()
          {
              string pattern = @"@[""]((?>[^""]+|[""]{2})*)[""]";
              string substitution = @"""$1""";
              string input = @"@"" @""text"" @""a\nb"" @""a""b"" @""a\""\""b""";
    • Result (in substitution field) on regex101: "" "text" "a\nb" "a""b" "a\""\""b"
    • Result (of "Code Generator" output) on try.dot.net: " @"text" "a\nb" "a"b" "a\"\"b"
  2. """...""" delimiter:

    • REGULAR EXPRESSION: @""((?>[^""]+|[""]{2})*)""
    • TEST STRING: @"" @"text" @"a\nb" @"a""b" @"a\""\""b"
    • SUBSTITUTION: "$1"
    • Code Generator snippet:
          public static void Main()
          {
              string pattern = """
      @[""]((?>[^""]+|[""]{2})*)[""]
      """;
              string substitution = @"""$1""";
              string input = @"@"" @""text"" @""a\nb"" @""a""b"" @""a\""\""b""";
    • Result (in substitution field) on regex101: "" "text" "a\nb" "a""b" "a\""\""b"
    • Result (of "Code Generator" output) on try.dot.net (after manually prepending @ to """): " @"text" "a\nb" "a"b" "a\"\"b"

Expected

  1. The delimiters should show @ before the """, """", """"".
  2. The Code Generator output should as well. Additionally, there should probably not be a newline after the opening """ and before the closing """, as shown above.
    • I would expect it to look the way the @"..." outputs now.
firasdib commented 9 months ago

Thank you, fixed locally