C
C
CityzenUNDEAD2021-07-02 12:42:57
Regular Expressions
CityzenUNDEAD, 2021-07-02 12:42:57

Why doesn't the regular expression work?

Good afternoon!
I am writing a parser in C# that should accept and process json. The resulting json contains a lot of unicode escape characters like \\u0420\\u043e\\u0441.
As I understand it, the main thing is to replace 2 slashes with 1, and then it will turn out to get the desired text.
I'm trying to do it with regular expressions.

string test = "\u0022\\u0420\\u043e\\u0441\\u0441\\u0438\\u044f\u0022";
string check = Regex.Replace(test, @"\\", @"\");

Console.WriteLine(check);

As a result, Unicode characters are still displayed in the console. How can I fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-07-02
@Zoominger

Try like this:

Regex  rx = new Regex( @"\\[uU]([0-9A-F]{4})" );
result = rx.Replace( result, match => ((char) Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString() );

Source: https://stackoverflow.com/questions/183907/how-do-...

S
SOTVM, 2021-07-02
@sotvm

I think it's about quotes
quotes " are not equal to ' or `
take it in single

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question