Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching Text with wildcard 1

Status
Not open for further replies.

majlumbo

Programmer
Jul 13, 2010
295
US
I have a function that searches documents for a keyword using the pos() function that works.

I want to extend this feature to allow for '*' and '?' as wild cards.

I've been able to code the asterisk using recursion and it seems to work (although if you are actually searching for an *, then it would not work correctly), but I cannot seem to figure out a way to code the question mark.

I've found many delphi functions that claim it can do wild card searches, but none seem to actually work for me.

Any ideas would be appreciated on how to accomplish this.

Thanks in advance...
 
Actually, that's a pretty good idea,

I'll need to parse the pattern to manually escape all the reg ex character like \[ \] etc, and change * to .

Do you know what is the equivalent in reg ex for '?' ?

I need to keep it simple and using the full power of reg ex for this function would make it too difficult for my users.
 
Looks like actually the . is equivalent to the ? (match exactly one character). it's the * (match 0-n characters) that I need to figure out.

I see that

. = match a single character of any value, except end of line.

 
Bingo on the . = ?

As for the asterisk, it doesn't match anything itself: it modifies the previous piece of the regex. For example:
Code:
A*     matches 0-n (uppercase) A characters
[0-9]* matches 0-n digits
.*     matches 0-n of any character
 
Thanks for the info. Did work it out already.
The last one is the one I was looking for. '.*'

I'm working with the regular expression component recommended by whosrdaddy (BTW thanks), only problem I have is that I have to put in a bunch of Application.ProcessMessages to keep the app from locking up for the user.

Does anyone know how to implement the events Match and MatchAgain in a thread?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top