Pattern Matching Functions
SenseTalk's Pattern Language lets you use natural language to define patterns that you can use in searches to match against text. You can use any of the following operators, commands, and functions with patterns in place of fixed text strings:
containsoperatoris inoperatorbegins withoperatorends withoperatoroffset,range,every offset,every rangefunctionsreplacecommanddeletecommandsplitcommand,split byfunctionnumber of occurrences offunction
The matches operator is used to test whether some text matches a pattern:
In addition, the operators and functions which are described below are specifically for use with patterns.
Match, Every Match Functions
Behavior: Use the match and every match functions to locate a pattern within text. The match function finds the first occurrence of the specified pattern, and every match finds every occurrence of the pattern in the source.
Parameters:
- the match of pattern (required): Can be specified using the Pattern Language Syntax within angle brackets ( < ... > ) or as a variable whose value is a pattern.
- in source (required): Can be specified as a quoted string, in a variable, or as an expression that yields text.
- after position (optional): Specifies a number for a character position within the text such that the search for the pattern match begins with the next character position.
- before position (optional): Specifies a number for a character position within the text such that the search for the pattern match ends with the character before that character position.
- caseSensitivity (optional): Specifies any of the standard case sensitivity phrases (
caseSensitive,with case, etc.), to determine whether searches for text are case sensitive or not. Default: as set bythe caseSensitivelocal property.
Syntax:
{the} match of pattern [in | within] source { [before | after] [ {position | location} position | {the} end ] } {caseSensitivity}
every match of pattern [in | within] source { [before | after] [ {position | location} position | {the} end ] } {caseSensitivity}match( pattern, source {, position {, caseSensitive {, treatPositionAsBefore }}} )
everyMatch( pattern, source {, position {, caseSensitive {, treatPositionAsBefore }}} )
When using the match() or everyMatch() traditional function call syntax, the first two parameters are required and the remaining three are optional. The caseSensitive parameter in this case is a boolean (default: False) indicating whether the search is case sensitive. The treatPositionAsBefore parameter is a boolean (default: False) that specifies whether the search should occur before the location given by the position parameter rather than after.
Returns: One or more property lists to provide information about locations in the source text where the pattern was found. The match function returns one property list, and every match returns a property list for each match found. Each match property list contains at least two properties:
text: The full text that was matched.text_range: The range of characters in the source where the matched text was located.
When the pattern contains one or more capture groups, the match property list also includes a pair of properties for each capture group included:
- name: The name of the capture group.
- name_range: The range where the capture group was found.
Because the full matched text is always returned with the property name text, you should not use the name text for any capture groups within a pattern.
Example:
put the match of <punctuation> within "Green 1: 112-14" --> {text:":", text_range:8 to 8}