Examples

These examples demonstrate pattern matching in the MatchRegex operator.

Example 1: A simple example of concatenation.

The predicates that are used in the example are:


param
	predicates:{
	big=i>1000,
	middle=i>10 && i<1000,
	little=i<10};
If you use a pattern of big little, a sequence of tuples where i has the values of:
  • 2000, 0 is a match.
  • 2000, 100, 10 is not a match, because the value 100 does not fit the pattern.

Example 2: A simple example of disjunction and grouping.

If you use the same predicates as the previous example, and a pattern of (big | middle) little:
  • 2000, 10 is a match.
  • 100, 10 is a match.

Example 3: A simple example of optional expressions.

If you use the same predicates as the previous examples, and a pattern of big middle? little:
  • 2000, 10 is a match.
  • 2000, 100, 10 is a match.

Example 4: Detecting patterns in stock prices.

In the following example, the input stream Quotes consists of stock price information over time. The task is to detect "M-shape" patterns, also known as double-peak formation. In other words, the pattern detects two rise and drop peaks, followed by a deep drop below the start of the pattern.


stream<MatchT> Matches = MatchRegex(Quotes) {
param
	pattern     : ". rise+ drop+ rise+ drop* deep";
	partitionBy : symbol;     
	predicates  : {
		rise = price>First(price)  && price>=Last(price),
		drop = price>=First(price) && price<Last(price),
		deep = price<First(price) && price<Last(price) };
output
	Matches : symbol=symbol, seqNum=First(seqNum),
	count=Count(), maxPrice=Max(price);
}