Description
Returns the number of regular expression matches between the calling String and the specified String argument. In order to return a match, the String argument must match the entire string - this can be accomplished using regular expressions. A successful pattern match always returns >= 1, where multiple matches come from user specified groupings.
|
|
.
|
Returns any character except \n (line feed), \r (carriage return)
|
|
|
{n}
|
|
{n,}
|
|
|
|
|
|
[...]
|
|
|
|
|
|
|
|
\Q...\E
|
Matches the characters between \Q and \E literally, suppressing the meaning of special characters
|
\d
|
Matches any decimal digits, can be used inside [...]
|
\w
|
Matches any word character, can be used inside [...]
|
\s
|
Matches any whitespace, can be used inside [...]
|
\D
|
Matches a character that is not a digit, can be used inside [...]
|
\W
|
Matches a character that is not a word character, can be used inside [...]
|
\S
|
Matches a character that is not a whitespace, can be used inside [...]
|
\n
|
Matches a line feed
|
\t
|
Matches a tab
|
*
|
0 or more of previous expression
|
+
|
1 or more of previous expression
|
?
|
0 or 1 of previous expression
|
Timing Precision Mode
This page describes functionality in nanosecond timing precision mode.
Click here to see the documentation for this object in millisecond timing precision mode.
Method Signature
String.Match(
|
String regularExpression)
|
Arguments
regularExpression
|
|
Description:
|
A regular expression that defines the pattern to match against.
|
Return Value
Returns the number of regular expression matches between the calling String and the regular expression specified by regularExpression.
Syntax
myVariable1 = myString1.Match(myString2);
|
String testStr = "the test string";
// This case will return a 0 indicating there is not return a match.
// "t" will be matched against the entire testStr string, however,
// the entire string contains more than just the character 't'.
Report testStr.Match("t");
// This will check the entire string to see if there any t's. It will return 1
// indicating a match if the string contains t's and 0 otherwise.
Report testStr.Match(".*t.*");
|
testStr.Match("t")
|
0.000000000
|
testStr.Match(".*t.*")
|
1.000000000
|
|
String testStr = "the test string";
// The first run below does not produce a match because the spaces in the
// string are not being accounted for. This is addressed by including \s
// in the second run.
Report testStr.Match("[a-z]*");
Report testStr.Match("[a-z,\s]*");
|
testStr.Match("[a-z]*")
|
0.000000000
|
testStr.Match("[a-z,\s]*")
|
1.000000000
|
|
String testStr = "the test string";
// In this case, 4 matches are returned. Each grouping indicates one word in the string
// to be matched, defined by (), using the given regular expressions. The same match
// could also be found using the regular expression \w as in the second example.
// The output of '4' indicates that each grouping was correctly matched as well as the
// entire string.
Report testStr.Match("([a-z]*) ([a-z]*) ([a-z]*)");
Report testStr.Match("(\w*) (\w*) (\w*)");
|
testStr.Match("([a-z]*) ([a-z]*) ([a-z]*)")
|
4.000000000
|
testStr.Match("(\w*) (\w*) (\w*)")
|
4.000000000
|
|
String testStr = "Apr 15 2011 09:50:02.000";
// Matching a string with word, special character, and digit input for a
//common date format
Report testStr.Match("\w{3} \d{2} [0-9]{4} \d+:\d+:\d+\.\d{3}");
|
testStr.Match("\w{3} \d{2} [0-9]{4} \d+:\d+:\d+\.\d{3}")
|
1.000000000
|
|
See also
String Object
String.Match
Parsing Dates and Times
Parsing Arbitrary String Data
Parsing Arbitrary String Data
|