See Pattern Matching in the Scripting Guide book for more detailed information on constructing and using pattern matching expressions.
p = "the beginning" + Pat Arb() >? stuffInTheMiddle + "the end";
Pat Match( "in the beginning of the story, and not near the end, there are three bears", p );
Show( stuffInTheMiddle );
stuffInTheMiddle = " of the story, and not near "
adjectives = "large" | "medium" | "small" | "warm" | "cold" | "hot" | "sweet";
rc = Pat Match( "I would like a medium hot, sweet tea please",
               Pat Arbno( adjectives | Pat Any(", ") ) >> adj +
               ("tea" | "coffee" | "milk") );
Show( rc, adj );
rc = 1;
adj = " medium hot, sweet ";
Constructs a pattern that matches the null string and stores the current position in the source string into the specified JSL variable (varName). The assignment is immediate, and the variable can be used with expr() to affect the remainder of the match.
p = ":" + Pat At( listStart ) + Expr(
	If( listStart == 1,
		Pat Immediate( Pat Len( 3 ), early ),
		Pat Immediate( Pat Len( 2 ), late )
	)
);
early = "";
late = "";
Pat Match( ":123456789", p );
Show( early, late );
early = "";
late = "";
Pat Match( "   :123456789", p );
Show( early, late );
early = "123"
late = ""
 
early = ""
late = "12"
type = "undefined";
rc = Pat Match(
	"green apples",
	Pat Conditional( "red" | "green", type ) + " apples"
);
Show( rc, type );
rc = 1;
type = "green";
type = "undefined";
rc = Pat Match(
	"green apples",
	("red" | "green") >> type + " pears"
);
Show( rc, type );
rc = 0
type = "green"
Pat Match executes the Pattern against the SourceText. The pattern must be constructed first, either inline or by assigning it to a JSL variable elsewhere.
Pat Match( "coffee with cream and sugar", "cream", NULL, ANCHOR );
Optional command to force Pat Match to try all alternatives, which uses more memory as the match expands. By default, Pat Match() does not use FULLSCAN, and makes some assumptions that allow the recursion to stop and the match to succeed.
Constructs patterns that match the null string if the current position is int from the left end of the string, and fail otherwise.
Constructs patterns that match the null string if the current position is int from the right end of the string, and fails otherwise.
Matches pattern between minimum and maximum times.
If GREEDY is specified, it tries the maximum first and works back to the minimum. If RELUCTANT is specified, it tries the minimum first and works up to the maximum.
Pat Arbno(p) is the same as Pat Repeat(p, 0, infinity, RELUCTANT)
Pat Repeat(p) is the same as Pat Repeat(p, 1, infinity, GREEDY)
Pat Repeat(p, n) is the same as Pat Repeat(p, n, infinity, GREEDY)
Pat Repeat(p, n, m) is the same as Pat Repeat(p, n, m, GREEDY)
Constructs a pattern that matches forward to position int in the source string. It can match 0 or more characters. It fails if it would have to move backwards or beyond the end of the string.
Usually the argument is wrapped with expr() because the test needs to be made on the current value of variables set by Pat Immediate, Pat Conditional, and Pat At. Without expr, the test is based on values that were known when the pattern was constructed, which means the test always succeeds or always fails at pattern execution time, which is probably not what you want.
nCats = 0;
whichCat = 3;
string = "catch a catnapping cat in a catsup factory";
rc = Pat Match(
	string,
	"cat" + Pat Test(
		Expr(
			nCats = nCats + 1;
			nCats == whichCat;
		)
	),
	"dog"
);
Show( rc, string, nCats );
rc = 1
string = "catch a catnapping dog in a catsup factory"
nCats = 3
Executes the pattern match in pattern against the quoted source string.