views:

49

answers:

1

Other than perhaps enhanced readability for very simple patterns, why would someone choose to use the Like operator in VB.NET over regular expressions for string pattern matching? Are there any advantages?

+2  A: 

Probably. If you want to take a look at how Like is implemented, much (all?) of it is in Microsoft.VisualBasic.CompilerServices.LikeOperator, and the rudiments can be seen in #LikeObject and #LikeString. Looking at the documentation, Like obviously uses a pretty strict subset of the full-on regular expression engine, and like just about any Perl-Compatible Regular Expression engine, there's some heavy lifting that may be overkill for simple expressions.

That said, in my opinion, it comes down to style. If you feel that If (myString Like "a?bb") is more readable, idiomatic, and consistent with the rest of your code, go for it. It would appear to me that going either way for anything but the aforementioned reasons is microoptimization theatre, especially since you can compile regexes if you need to.

Marc Bollinger