0

I have an old perl regex defined like this

my @data = split(/^[0-9]{1,3}\)?\t/m, $CLIP->GetText());

C# doesn't like the regex and says Unrecognized escape sequence? How can i fix this?

I tried this in C#

Regex rex = new Regex("/^[0-9]{1,3}\)?\t/m");
2
  • Did you type that in literally... you need to use C# constructs... strings, Regex etc. Commented Nov 22, 2012 at 0:22
  • yeah my friend told me it would work... I know little of perl, c# and regex's so i came here for help Commented Nov 22, 2012 at 0:24

1 Answer 1

2

The problem is \). The easiest way to fix the problem is by changing the string to a verbatim string like this:

Regex rex = new Regex(@"^[0-9]{1,3}\)?\t");

Also, you don't need the slashes and the trailing m in this case.

Sign up to request clarification or add additional context in comments.

2 Comments

Aren't the starting and ending slashes (and m) not actually part of the regular expression? It looks to me like how it is in javascript.
@cowboydan The question is tagged with C# 4, so that should not be a problem. However, since this is not essential to the issue, I have removed the use of var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.