Regular Expressions in Filters

You can apply a regular expression to any filter variable that is a String data type.

You can return whether a regex matches: /<regex>/.test(<variable>)

You can also use a capture string and compare the captured string to another string: /<regex(capture)>/.extract(<variable>), which returns the captured string.

  • /DF(\d\d\d\d)/.extract(sample_name) = '1234'// Captures the four digits from the regex and tests against '1234'.
Note:
  • The examples above use the view-level variable sample_name, which evaluates to a String. If you attempt to use a String data type axis variable, those variables may evaluate to a vector of strings, since there may be multiple instances of the axis variable within a single view. In this case, the regex must be applied within the axis filter, as shown below:

    match[/FH\d\d\d\d/.test(feature A feature is a visually distinguishable area in an image. Features typically represent something of interest for the application (a defect, an object, a particular component of an object)._string)]// For this expression, the regex is applied for each match's feature_string. If any of the matches' feature_string match the regex, the view will be included.

    The following is an example of an invalid regex filter expression:

    /FH\d\d\d\d/.test (match/feature_string)// The expression should return true if the view includes a match with a feature_string matching the regex. However, this is invalid, because each view may have multiple matches.

  • You cannot use the sets variable in a regular expression.