1

I've got a RegEx that works great on *NIX systems and languages that support Extended Regular Expressions (ERE). I haven't found a freely available library for .NET that supports ERE's, nor have I had any lucky trying to translate this into a non-ERE and get the same result. Here is the RegEx:

^\+(<{7} \.|={7}$|>{7} \.)

Background: the point of the RegEx is to identify if a given string appears to have the markers from an unresolved subversion merge.

2 Answers 2

4

It looks to me like ERE syntax is mostly upward-compatible with .NET's regex flavor, as it is with most other "Perl-compatible" flavors (Perl, PHP, Python, JavaScript, Ruby, Java...). In other words, anything you can do in an ERE regex, you should be able to do in an identical .NET regex. Certainly your example:

^\+(<{7} \.|={7}$|>{7} \.)

means the same thing in .NET as it does in ERE. The only major exception I can see is in the area of POSIX bracket expressions; .NET follows the Unicode standard instead.

It's when you go to apply the regex that things really get different. In C# you might apply that regex like this:

string result = Regex.Match(targetString, @"^\+(<{7} \.|={7}$|>{7} \.)").Value;

C#'s verbatim strings save you having to escape backslashes like in some other languages' string literals; you only have to escape quotation marks, which you do by doubling them:

@"He said, ""Look out!""";

Does that answer your question?

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

1 Comment

That didn't answer it, but I did learn something new - I hadn't realized C# allowed the double-quote method of escaping quotes. I was using the "@" to declare the string literal.
0

Are you sure you don't have a typo in that? RegexBuddy (when set to either POSIX ERE or GNU ERE) says that the "+" quantifier must be preceded by a token that can be repeated. Other than that, this appears to be a valid .NET Regex. You might want to check out one of the great O'Reilly books on regular expressions as well. If this doesn't help, please post some examples of text you're trying to match/not match.

1 Comment

It's not a typo, the OP just didn't use code formatting, so the SO software ate some of the characters.

Your Answer

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