Re: Search Ambiguous



Too simplistic I'm afraid Rick

Suppose the pattern has multiple instances of '*', e.g.
<frag1>*<frag2>*<frag3>, and/or occurrences of ?/#.

The starting point for matching frag2 depends on the accuracy of the match
for the next *<frag3>, and so on down the string. It cannot be done without
recursion or some internal stack remembering the current guess for the
starting point of each '*'

Also, it only returns one text fragment as opposed to some array of
fragments matching each of the wildcard characters

Tony Proctor

"Rick Rothstein (MVP - VB)" <rick.newsNO.SPAM@xxxxxxxxxxxxxxxxxx> wrote in
message news:%23JDtIyTBJHA.4724@xxxxxxxxxxxxxxxxxxxxxxx
What about this modification to the function I posted earlier in this
thread? I *think* it does what you are saying without needing recursion...

Function AmbiguousFindAndReturn(TextString As String, _
Pattern As String) As String
Dim X As Long
Dim Z As Long
Dim Location As Long
Do While Left(Pattern, 1) = "*"
Pattern = Mid(Pattern, 2)
Loop
For X = 1 To Len(TextString)
If Mid(TextString, X) Like Pattern & "*" Then
Location = X
For Z = 1 To Len(TextString) - Location + 1
If Mid(TextString, Location, Z) Like Pattern & "*" Then
AmbiguousFindAndReturn = Mid(TextString, Location, Z)
Exit Function
End If
Next
End If
Next
End Function

Rick


"Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:O1ZHU1RBJHA.1184@xxxxxxxxxxxxxxxxxxxxxxx
Are you interested at all in identifying the actual text matching the
wildcard markers Lorin? For instance, given a pattern of "Today is *. The
time is ##:##" and a string of "Today is Saturday. The time is 13:35",
something that would give you the "Saturday", the "13" and the "35".

I needed to do this a while back for a regression-test suite and couldn't
find anything that did what I wanted. I eventually wrote something
myself. It was an interesting recursive problem since the new starting
point after a "*" depends on the success of subsequent matches. The
advantage of writing my own algorithm was that I could add specialised
markers to represent higher-level concepts that were more relevant to the
application

Tony Proctor

"Lorin" <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:370A999E-BAE5-4DD6-B5F0-76FA0998702F@xxxxxxxxxxxxxxxx
VB6
Looking for help developing a string Search Ambiguous routine.
Something like the Find 'Use Pattern Matching' in the VB6 IDE would be
OK.

What I am planning to try is
Use 'Like' to see if the Search String is there.
Then use a combination of Instr and Mid$ to do the work.
That gets complex based on the Like pattern matching operators.
I guess I could limit it to * and ?

Hoping there is an easier/faster way than that.
Is there an API that will do this on a string?

I really would like to have a Like function that would return the
location
of the first chartacter of the Like match not just that it found it or
not.
How do I do this?






.



Relevant Pages

  • Re: array or with non-array
    ... David A. Black wrote: ... > matching an IO object to a pattern. ... > there *should* be an explicit, intervening string representation. ... This works pretty well for every pattern without anchors. ...
    (comp.lang.ruby)
  • Re: [RCR] array or with non-array
    ... This requires the arg to be a String. ... I'm not sure how much more polymorphic one could get, unless one had every object present its .to_s representation for matching, which would not be good. ... The object has to match the pattern, and the patterns are descriptions of strings. ... # pos can go beyond the eof ...
    (comp.lang.ruby)
  • java regex help
    ... For ex: if the String is ... after the pattern matching ... I think my regular expression pattern might be ...
    (comp.lang.java.help)
  • java regex help
    ... For ex: if the String is ... after the pattern matching ... I think my regular expression pattern might be ...
    (comp.lang.java.softwaretools)
  • Re: A couple of questions regarding runtime generation of REGEXPs
    ... Apparently qr// will only function on the matching side, ... makes that kind of operation work on some other string. ... argument is a search pattern, substitution, or transliteration. ... Regexp Quote-Like Operators ...
    (comp.lang.perl.misc)