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.
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.
Taken from the link on Visual Studio Regular Expressions
Note: There are many syntax differences between the regular expressions that can be used in Find what and Replace with and those that are valid in .NET Framework programming. For example, in the Find and Replace window, braces {} are used for tagging expressions to be replaced: to change every occurrence of doesn't to does not, you would use the find expression {does} and the replace expression \1 not. This regular expression syntax differs from .NET Framework, where the notation {} is used for quantifiers, so that the expression zo{1} would match all occurrences of z followed by exactly one o, as in zone but not in zoo.
The primary differences are syntactical, though Visual Studio does try to slip in a little more functionality than the standard Regular Expression library uses.
精彩评论