|
Don't worry, I'n not going to go into detail on Regular Expressions. I'm no expert. There are other, better, places to go for help with Regular Expressions.
Like here. Instead I just wanted to show you how you can now use Regular Expressions, and something far easier called
Easy Patterns, in Macro Scheduler 11.1.05.
I don’t know many people who find Regular Expressions easy. If the following makes no sense to you, don’t worry, you’re not alone:
([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)
*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)
It’s actually a regular expression pattern which will match an email address in a string. I’m sure you knew that.
Until 11.1.05 to use Regular Expressions in Macro Scheduler you had to use VBScript’s regular expression object:
VBSTART
Function RegExpTest(sEmail)
RegExpTest = false
Dim regEx, retVal
Set regEx = New RegExp
regEx.Pattern ="([a-z0-9!#$%&'*+/=?^_`" & _
"{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)" & _
"*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)" & _
"+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"
regEx.IgnoreCase = true
Set retMatches = regEx.Execute(sEmail)
If retMatches.Count > 0 then
RegExpTest = retMatches(0).Value
End If
End Function
VBEND
VBEval>RegExpTest("My email address is: freddy@mjtnet.com"),theEmail
MessageModal>theEmail
In order to simplify things we have now introduced a native Regular Expression function called, appropriately enough, RegEx:
RegEx>pattern,text,easypatterns,matches_array, num_matches,replace_flag[,replace_string,replace_result]
Using this, the following code will find the email address in the given string:
Let>text=My Email Address: freddy@mjtnet.com
Let>pattern=([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\....[Snipped]
RegEx>pattern,text,0,matches,num,0
MessageModal>matches_1
A bit simpler, as you don’t need to use VBScript. But you still need to use that weird and wonderful regular expression syntax.
Luckily our friends at DataMystic have created something called EasyPatterns which maps real English to regular expression syntax. Thanks to DataMystic we are able to use EasyPatterns in Macro Scheduler. Setting the EasyPatterns flag in the new RegEx command allows us to turn the above into:
Let>text=My Email Address: freddy@mjtnet.com
Let>pattern=[EmailAddress]
RegEx>pattern,text,1,matches,num,0
MessageModal>matches_1
Note the second line has been simplified to Let>pattern=[EmailAddress]. Nice. Now it makes sense!
Check out the EasyPatterns Reference here to find out what else you can do.
The new RegEx function also does search/replace. The following example will replace all IP addresses found in the string with 127.0.0.1:
Let>text=Server: 196.128.1.1; Gateway 196.128.1.10
Let>pattern=[IPAddress]
RegEx>pattern,text,1,matches,num,1,127.0.0.1,text
The following code will remove all null chars from a string:
RegEx>\0,text,0,matches,num,1,,text
A simple back reference example:
Let>text=fff axaxa fffddd bxbxb silly cxcxc
Let>pattern=([a-c])x\1x\1
RegEx>pattern,text,0,matches,num,0
Let>k=0
Repeat>k
Let>k=k+1
Let>this_match=matches_%k%
MessageModal>this_match
Until>k=num
The above code will find and return substrings axaxa, bxbxb an cxcxc.
Remember - you need Macro Scheduler 11.1.05 to use the new RegEx function.
|