http://stackoverflow.com/questions/21800742/regular-expression-using-vbscript-for-starting-characters/21801104?noredirect=1#21801104
Symbols:
! =
^ = this is carat operator to identify beginning of sting. Ex: "^a" , Ex: "^(AET)". Only match the beginning of a string 'AET' here.
* = Matches one or more times. Ex: ".*" ..matches any character any number of times.
. = Matches any characters
() = this is useful to combine operations
"" = matches any character between " ". Any characters b/w "", will check if that chars are present in string.
| =This is OR operator
? = Matches the previous element one or more time
[] = You can create a list of matching characters by enclosing one or more individual characters in brackets [ ]. Match any one character enclosed in the character set.
{} = Match exactly x occurrences of a regular expression.
\ = matches the above character in the string, to make them not do there operations. Ex: string= "AET*" , to match this "*" in string, pattern is ".*(\*)"
$ = Only match the ending of a string. "t$". Ex: "Tight"
\b = Matches any word boundary. "ly\b" matches "ly" in "possibly tomorrow."
\B = Matches any non-word boundary.
[^xyz] - Matches any one character not in the set. Both opening and closing brackets are required.
Example "[^abc]" matches the "p" in "plain
[^a-z] - Matches any character not in the specified range.
Example "[^m-z]" matches any character not in the range of "m" through "z".
| Quantifier | Explicit quantifier | Meaning |
|---|---|---|
| * | {0,} | Matches the previous element zero or more times. |
| + | {1,} | Matches the previous element one or more times. |
| ? | {0,1} | Matches the previous element zero or one time. |
Method:
-Execute()
-Matches()
' Code for regular expression
Sub validatingtext()
Set RegularExpressionObject = CreateObject("vbscript.regexp")
src = "AET_P1s_ dfd"
RegularExpressionObject.IgnoreCase = True
RegularExpressionObject.Global = True
RegularExpressionObject.Pattern = "^(AET|BUS)_.*_.*"
'RegularExpressionObject.Execute (src)
Set Matches = RegularExpressionObject.Execute(src)
If (Matches.Count <> 0) Then
MsgBox ("True")
Else
MsgBox ("False")
End If
End Sub
No comments:
Post a Comment