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

HI,

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()

Regards,

This is my text:
AnswerKey,valuePassport-Number,6566666666666

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

Hi,

Can you try to remove ^ as the following?

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

Regards,

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?

Hi,

@ 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

Regards,

Thanks @Yoichi for your quick response…

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