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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp Help 1

Status
Not open for further replies.

bjd4jc

Programmer
Nov 8, 2001
1,627
US
I have create a Regular Expression that will work if it has to but would like to refine it down a little more if I can. Here is what I have so far.

Code:
Public Function gloGetKeywordValues(lstrKeyWords As String, lstrFieldName As String, DelimitBy As String) As String
    Dim lRegExp As RegExp
    Dim lMatches As MatchCollection
    Dim lMatch As Match
    
    Set lRegExp = New RegExp
    
    lRegExp.Pattern = "(" & lstrFieldName & ")[^\n]*\n"
    lRegExp.IgnoreCase = True
    lRegExp.Global = True
    
    Set lMatches = lRegExp.Execute(lstrKeyWords)
    
    gloGetKeywordValues = ""
    For Each lMatch In lMatches
        gloGetKeywordValues = gloGetKeywordValues & DelimitBy
    Next
End Function
Assume this is the contents of lstrKeywords (include crlf):
SUBJ=Testing
RET=238826
RET=247142
DTD=Affidavits

!!

I am sending RET= to the value of lstrFieldName and the delimiter can be anything.

I want to use the RegExp to eliminate the crlf and the RET= (whatever is in lstrFieldName). I can't figure out if is possible to exclude them using the Regexp. So if the Delimiter is a "~" and all other variables are as discussed the function would return "238826~247142~". Can someone confirm or deny the possiblity of this??

Thanks
 
I'm not sure if its what you're looking for, but I did get a RegExp to return the values you wanted:

lRegExp.Pattern = "[^" & lstrFieldName & "][\d]+"

I called the function like this:

s = "SUBJ=Testing" & vbCrLf & "RET=238826" & vbCrLf & "RET=247142" & vbCrLf & "DTD=Affidavits" & vbCrLf & vbcrlf & "!!"

MsgBox gloGetKeywordValues(s, "RET=", "~")

and the function returns "238826~247142~".

Note that this expression only works with numeric values. I have been trying to develop one that will look for numeric, alpha and alphanumeric values but I am having little success so far.

Let me know what you think.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
This is a really good starting point and maybe I can get it from here. But, this is the problem with it. Let's now say that I have another entry in my keyword list.

DOC=99999

Then the string would return 238826~247142~99999~" even though it is not the RET value. For now I am going to use what I have and use the replace function to eliminate what I don't need.

I appreciate your help jebenson!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top