danitouffaha
New Member
- Joined
- Nov 16, 2012
- Messages
- 18
I want to write a regular expression in vba that accepts 1,2 or 3 (-) or 1,2 or 3 (+) and series of digits(0-9), and it can repeat
so for example +++5+2-10+6 is accepted
++++5 is not accepted because there 4 (+) as well as ----10+2 not accepted because there are 4 (-)
I have tried many regex that did not work
I think it should be easy but couldnt find anything to help me resolve it
Thanks
so for example +++5+2-10+6 is accepted
++++5 is not accepted because there 4 (+) as well as ----10+2 not accepted because there are 4 (-)
I have tried many regex that did not work
VBA Code:
Sub Test_Pattern()
Dim Str As String
Dim regexObject As RegExp
Set regexObject = New RegExp
With regexObject
'checks if any word in our string start with an alphabet between W and Z
.pattern = "[\+|\+\+|\+\+\+][0-9]{1,}"
End With
Str = "++++55"
'A message box displays true because we have a word starting with W ‘World’
MsgBox regexObject.test(Str)
End Sub
I think it should be easy but couldnt find anything to help me resolve it
Thanks
Last edited by a moderator: