Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the difference between .NET regular expressions and Visual Studio's regular expressions?

I've finally found references to both Visual Studio's regular expressions for Find and Replace, and .NET's regular expression package, and now out of morbid curiousity I want to know: why the difference!?

I'm sure there's a technical, historical, or usability reason, but it confused the bajeepers [sp? ;-) ] out of me at first.

like image 922
Chris Pfohl Avatar asked Mar 03 '11 14:03

Chris Pfohl


People also ask

What is difference between regex and regular expression?

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

What is the difference between .*? And * regular expressions?

*1 , * is greedy - it will match all the way to the end, and then backtrack until it can match 1 , leaving you with 1010000000001 . . *? is non-greedy. * will match nothing, but then will try to match extra characters until it matches 1 , eventually matching 101 .

What is .NET regex?

In . NET, regular expression patterns are defined by a special syntax or language, which is compatible with Perl 5 regular expressions and adds some additional features such as right-to-left matching. For more information, see Regular Expression Language - Quick Reference.

What are different types of regular expression?

There are also two types of regular expressions: the "Basic" regular expression, and the "extended" regular expression. A few utilities like awk and egrep use the extended expression. Most use the "basic" regular expression. From now on, if I talk about a "regular expression," it describes a feature in both types.


1 Answers

I'd speculate that the VS regexes are designed to match code well, having defined lots of handy shortcuts like :w for an entire word, or :i for a C++ identifier, or :q for a quoted string.

They usually don't need to handle arbitrary data that you'd need lookaround assertions and stuff like that for. Or at least that was lower on the priorities list.

like image 190
Tim Pietzcker Avatar answered Nov 24 '22 01:11

Tim Pietzcker