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

regexp/match help

Status
Not open for further replies.

scifi99

Programmer
Nov 12, 2001
1
0
0
US
Being new to vbscript I don't understand how these 2 work.
I have a string variable and I want to identify
if 3 characters within the string are equal to multiple potential characters. I need to know if the string variable contains ABC or HIJ or LMN or STU, how do I do this?
 
ABC or HIJ or LMN or STU, how do I do this?

Do you need to know which string it contains, or just if it contains one of those strings?

For the latter:

If InStr(strVariable, &quot;ABC&quot;) <> 0 OR InStr(strVariable, &quot;HIJ&quot;) <> 0 OR InStr(strVariable, &quot;LMN&quot;) <> 0 OR InStr(strVariable, &quot;STU&quot;) <> 0 Then
'perform task for string exists condition
Else
'perform task for strings don't exist condition
End If

For the former, just compare for each string individually and act accordingly.

Is this what you are asking?
 
I think he wants to use regular expressions to accomplish the same thing.

If only I could figure them out myself!

Another alien concept from the Unix world I'm afraid.
 
Try something like this:
Dim testString, objRegExp
testString = &quot;blahABCblah&quot;
Set objRegExp = new regexp
objRegExp.Pattern = &quot;ABC|HIJ|LMN|STU&quot;
If objRegExp.Test(testString) Then
MsgBox(&quot;TestString contains one of the substrings&quot;)
End If
 
Thank You for all your help. Yes I was trying to use regexp to accomplish the same thing. Thought that was the only easy way. Sorry about being such a rookie, being an old cobol and basic programmer (not VB) am just starting to learn vbscript/vb6 and loving it.
Thanks Again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top