abenitez77
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 149
I have a variable with a string...and I want to know if it contains any value other than single quote, comma and a space ("', ") I'm using vba in excel. for example, i have a variable
This should return > 0:
strA = "'test', 'player'"
I want to check to see if strA has any characters other than "', " (single quote, comma and space).
This should return 0
second example:
strA = ",'"
I tried using regex but I'm getting a match when i only have comma, single quote and space. Can someone help ?
This should return > 0:
strA = "'test', 'player'"
I want to check to see if strA has any characters other than "', " (single quote, comma and space).
This should return 0
second example:
strA = ",'"
I tried using regex but I'm getting a match when i only have comma, single quote and space. Can someone help ?
Code:
If RegexCountMatches(" ',',' ',''", "\S[^,']") > 0 Then
msgbox("found match")
Endif
Public Function RegexCountMatches(str As String, reg As String) As String
On Error GoTo ErrHandl
Set regex = CreateObject("VBScript.RegExp"): regex.Pattern = reg: regex.Global = True
If regex.test(str) Then
Set matches = regex.Execute(str)
RegexCountMatches = matches.Count
Exit Function
End If
ErrHandl:
RegexCountMatches = CVErr(xlErrValue)
End Function
Last edited: