How do I use vbscript to find two texts that match within a singe line? For example:
This UserName is Logged on already.
How do I search for "UserName" and "Logged on"?
Regular expressions are probably overkill in this case. I'd suggest using InStr() for this kind of check:
s = "This UserName is Logged on already."
If InStr(s, "UserName") > 0 And InStr(s, "Logged on") > 0 Then
'...
End If
You can wrap InStr() in a helper function if you want to make the check a bit better readable:
s = "This UserName is Logged on already."
If Contains(s, "UserName") And Contains(s, "Logged on") Then
'...
End If
Function Contains(str1, str2)
Contains = False
If InStr(str1, str2) > 0 Then Contains = True
End Function
|.UserName.*Logged on?^This (.+) is (.+) already\.$on aGlobalsearch. Capture the matches.Usernameshould be inmatches(0).submatches(0),Logged oninmatches(0).submatches(1).