View Single Post
  #1   Report Post  
vigi98
 
Posts: n/a
Default Regular expressions in Excel

Bob Phillips wrote:
You can use Regular Expressions if you use VBScript.RegExp, creating a
function that you can use.

Here is an example that validates email addresses.


'-----------------------------------------------------------------
Public Function ValidEmail(Adress As String) As Boolean
'-----------------------------------------------------------------
Dim oRegEx As Object
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
' .Pattern = "^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$"
ValidEmail = .Test(Adress)
End With
Set oRegEx = Nothing
End Function


Thanks a lot for that, it works perfectly. Now, another question: is it
possible to have regular expression variables like under unix (for
instance if you have a regexp like "aaa(.*)bbb(c+)ccc", can you use the
variables $1 and $2 afterwards ?