Wildcard String Search

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm looking to do wild card pattern matching on strings. Here is an example:
Search string:
Begin * end?
New line with additional content*

Would match:
Begin at the end.
New line with additional content will appear here

Can anyone point me to an API that converts wildcard expressions to regular
expressions or can do string searching based on regular expressions?

Thanks,
Stuart
 
Correction, I would like and API to do string searching based on wild cards?

Thanks
-Stuart
 
The VB.Net 'Like' operator does wildcard comparisons, according to a
specific but not particularly powerful syntax.

The .Net Regex class, in the System.Text.RegularExpressions namespace, can
be used to do extremely powerful expression searching. I've never seen any
code that will take an arbitrary 'Like' expression and convert it to a
regular expression, but since the Like operator's syntax is pretty simple it
doesn't look like it would be difficult to do conversions. Anyway, the Regex
class is your starting point.

HTH,
Tom Dacon
Dacon Software Consulting
 
Thanks Tom...

I was using C# but that got me what I needed. For others looking for this
information, the corresponding method to use from C# is
Microsoft.VisualBasic.CompilerServices.Operators.LikeString

-Stuart
 
I agree, I like RE. The issue is that they are significantly more
complicated for folks (even programmers) unfamiliar with them. Therefore, I
want to provide an API that supports both wild cards and RE. In other words,
I would like the simplicity of wildcards for the end user.

I guess you could ask the same question of the VB language developers when
they created the Like operator. :)

-Stuart
 
I did the same sort of thing when I wrote my general-purpose find/replace
dialog in C#. I've got a dropdown list on the Find tab that supports exact,
wildcard, and regex searching. I put the wildcard rules into the HelpString
for the control, just as a reminder.

For me, it's easier to construct simple search strings with wildcards than
with regular expressions, since regular expressions are so finicky about the
syntax. Not to mention that a simple wildcard pattern can require such an
ugly and complicated regex pattern. And I can't imagine anyone except a
programmer actually being successful at writing regular expressions.
Probably no more than one percent of professional programmers are competent
at it.

Tom Dacon
Dacon Software Consulting
 
Back
Top