Regular Expression unrecognized escape sequence

I have the output for to extract the string after the text:

System.Text.RegularExpressions.Regex.Match( filtereddata,“(?<=^Passport-Number\W)(\w.*)$”).Value.ToString()

My project is in C#

so it was displaying like unrecognized escape sequence

Can someone help me on these


As the simplest way, can you try to add @ just before first double quote as the following?

System.Text.RegularExpressions.Regex.Match( filtereddata,@"(?<=^Passport-Number\W)(\w.*)$").Value.ToString()


This is my text:

and i need to get the Passport-Number

Here is my expression:
System.Text.RegularExpressions.Regex.Match( filtereddata,@“(?<=^Passport-Number\W)(\w.*)$”).Value.ToString()

But my output was in empty


Can you try to remove ^ as the following?

System.Text.RegularExpressions.Regex.Match( filtereddata,@"(?<=Passport-Number\W)(\w.*)$").Value


1 Like

Thanks man, got the solution

1 Like

Hi @Yoichi Can you please tell me why you are adding ‘@’ symbol before the regex code?


@ is defined to indicate string literal is to be interpreted verbatim.

Please see the following document - section2.

The following will also work (without using @ character)

System.Text.RegularExpressions.Regex.Match( filtereddata,"(?<=Passport-Number\\W)(\\w.*)$").Value


Thanks @Yoichi for your quick response…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.