-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# Code Gernerator: the substitution variable code is incorrect #2325
Comments
What is the error? The generated code looks correct. |
https://regex101.com/r/um4Khe/1 This provided regex example aims to append a horizontal tab character ( The correct result is obtained: While the 101 regex tester correctly produces the desired output Here's the generated C# code, which you can paste into Online C# Compiler (Editor) to test. using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"$";
string substitution = @"\t""";
string input = @"abc";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
// add lines to print the result
Console.WriteLine($"output: {result}");
Console.WriteLine($"length: {result.Length} characters");
}
} This code outputs:
That means the final result is |
Ah, you are correct. What would be the correct approach? |
This is an automatic reply, confirming that your email was received. I will reply as soon as possible. Thank you!
|
Here it is for your reference: // How to generate the code `string substitution = xxx;`
// "replacement text" received from the user
let repl = document.getElementById('sustitutionBox').value;
// escape double quotes with a backslash, leaving other characters unchanged
let literal = repl.replace(/\\.|"/g, m => m === '"' ? '\\"' : m);
// the generated code we expect
let code = `string substitution = "${literal}";`;
alert(code); // output: string substitution = "\t\""; |
Code Generator Language
C#
Question Description
Test Example: Insert a tab and a double quote at the end of a string
https://regex101.com/r/um4Khe/1
The code generated by the 101 Code Generator is as follows:
Among these, this line of code is incorrect:
string substitution = @"\t""";
The correct code should be:
string substitution = "\t\"";
Code Snippet
Here is the js code to generate the C# code for substitution variable:
The text was updated successfully, but these errors were encountered: