Skip to content

ChronEx Pattern Specification

mbadler edited this page Jun 13, 2018 · 13 revisions

Proposed Spec

Elements

  • Patterns are composed of elements separated by line breaks
  • An element can be a Selector or a Group
  • Selectors are positioned at the beginning of the group indentation level
  • Groups start with a grouping mark and end with a grouping mark (for example the ( ) marks )
  • after each element you can place a quantifier (similar to the regex quantifiers)
  • Additionally you can add filter directives to a selector - this will modify the selector so that the selector will only match if the filter matches

Selectors

  • Selectors are items that match and event
  • Only one selector per line

Direct Selector

A direct selector is a selector which appears in the pattern directly

For example this selector will match the Page_Loaded event as is

Page_loaded

Quoted Selector

A direct selector for complex event names with characters that would otherwise be invalid . the selector is surrounded with single quotes

For example this selector will match an event called Click (First)

'Click (First)'

You can include a single quote in the selector by escaping with a slash. stand alone forward slashes don't need to be escaped

'Bob\'s Event\s'

Wildcard Selector

A wildcard selector is denoted with a . and will match any event

Example: This pattern will match a Page_loaded event followed by any single event followed by a Page_unloaded event

Page_Loaded
.
Page_Unloaded

Regex Selector

A selector can be a RegEx expression that is matched against selector names regex selectors are defined similar to javascript regex literals by surrounding it with a // marks

Example: This pattern will match a page load event followed by any event named click followed a page unloaded event

Page_Loaded
/Page_.*Click/
Page_Unloaded

Capturing

By default any event that matches a selector will be captured to the match result , You can specify that the events match by a specific selector not be captured to the output by prepending the selector with a minus symbol ( - )

Example: If we had a list of events that started with a Start event and ended with a End Event and we wanted to only find matching Start and End events but we did not want capture all of the events in between.

Start
-!End*
End

Selector Quantifiers

Similar to regex , a selector can have a quantifier that will match only if the event match the quantity specified

NOTE: All quantifiers are considered "Lazy"

Symbol Quantifiers

Symbol quantifiers use a 1 char symbol to specify the quantity of events that need to match

The following quantifiers are supported:

Symbol Description
* Matches 0 or more events, if there are any events then they are captured if there aren't any then nothing s captured
+ Matches at least 1 event but will capture all matching events
? Matches only if there is non or at most 1 events, if there is one event then it is captured

Example: This pattern will only match a linkclicked event if it happens at least once (but it may happen more then once)

Link_Clicked+

Numeric Quantifiers

Numeric quantifiers match based on a provided amounts of events.

Numeric Quantifiers are expressed in the following format:

Quantifier Description
{X} Match exactly X events
{,X} Match from 0 up to X events
{X,} Match at leat X events
{X,Y} Match at least X but no more then Y events

Example: This pattern will only match a linkclicked event that happens at least 3 but not more than 5 times in a row

Link_Clicked{3,5}

Negated Selector

A negated selector will match any event next in the list if it is not the specified events. it is denoted with a !

Example: This pattern will match any link click that is not immediately followed with a page load (unless the session ended)

Link_Clicked
!Page_Load

Groups

Groups allow you to group selectors together for logical operations. unlike regex , groups in ChronEx are more expressive due to the nature of the expression layout (single char vs line delimited).

Groups are always indented with the beginning braces inline with the elements above and the group contents indented with at least one tab or space

Group

A group starts with a open pare and closes with a close paren. The group will only match if the full sequence of the group matches

Example: This pattern will match a sequence of events of page_load and then 2 linked_clicks

(
  Page_Load
  Link_clicked
  Link_clicked
)

A group is an element so a group can have a capture specifier and a quantifier, groups can also be nested

Note: At this time negated And Groups are not supported

Example: This pattern will match a Page_load and then at least 1 group of either a Link_clicked or Button_clicked which are not captured followed by a page_load

Page_Load
(
  -[
     Link_clicked
     Button_clicked
   ]{1,3}
   Page_Load
)+

Alteration (or) group

An or group starts with a open [ brace and ends with a close ] brace. The group will match if any of the selectors match

Example: This pattern will match a Page_load followed either by a Link_clicked and then immediately a Page_unload or followed by a add_to_cart. Note the sub and group

Page_Load
[
  (
    Link_Clicked
    Page_Unload
   )
   Add_To_Cart
]

Note: The pattern engine will perform a "Depth First" search on the element so if you have nested groups withing the or, the engine will first process the first item in the list to determine if its a match before moving on to the next item in the Or group

Negating a group

Similar to a selector a group can be negated by prefacing its opening bracket with a caret.

Example: this pattern will match a Page_Load that is not immediately followed by a Link_Cliked or a Add_to_Cart

Page_Load
![
  Link_Clicked
  Add_to_Cart
]

Captures

Similar to regex you can specify that an element should be captured on match. ChronEx only supports named captures and will not capture groups by default. You can capture a single event both top level and within groups. You can also capture a group.

To specify a element is to be captured you append the selector with #CaptureName:

Example: this pattern will match a Page_Load that is immediately followed by a Add_to_cart, Additionally the add_to_cart will be captured and returned with capture name ADDTOCART

Page_Load
#ADDTOCART:Add_to_Cart

You can also specify named captures on a negated selectors.

Example: this pattern will match a Page_Load that is not immediately followed by a Add_to_cart, Additionally the event after the pageload will be captured and returned with capture name NOTADDTOCART

Page_Load
#NOTADDTOCART:!Add_to_Cart

Group Captures

You can specify a capture on a group in which case the first event within the group to satisfy the group logic will be captured.

For And groups: If the group matches this will be the first event in the group For Or groups: This will be the first item that satisfies the short circuit condition

Clone this wiki locally