• Overview
  • Functions
    • Overview
    • action
    • connect
    • count
    • create_issue
    • create_vertex
    • dateprint
    • delete_vertex
    • disconnect
    • eject_issue
    • execute
    • find_timeseries
    • goto
    • html_extract
    • if
    • javascript
    • log
    • query
    • read_attachment
    • read_timeseries
    • read_vertex
    • regex
    • replace
    • sleep
    • split
    • stop_issue
    • suspend
    • suspend_until
    • update_vertex
    • write_attachment
    • write_timeseries
  • Definitions
  • Automation Issue Lifecycle
  • KI Best Practices
  • KI Debugging

Definition

This can by used to extract part(s) of a string using a regular expression.

The internal Elixir regex library is used, which is based on PCRE (Perl Compatible Regular Expressions). Please refer to the Elixir documentation for further details.
If the string is already being matched in an on or when section, a named capture in that match is usually the better choice. It avoids writing the pattern twice and can extract several submatches at once. See Named captures.

Usage

result: LOCAL::RESULT = regex("<text to be matched>", expression: "<regex expression>")
Table 1. Arguments
Position Keyword Required Description

1

string

X

String onto which the regex is applied

2

expression

X

Regular Expression, needs at least one SubMatch-Pattern. e.g. "Value: (0-9+) Seconds"

3

options

Modifiers for creating the Regex, e.g. "i". A full list of modifiers is available in the Elixir documentation.

 

Table 2. Return Values
Tag Description

result

Extracted substring

resultN

Nth extracted substring (optional depending on regex)

Example

result: LOCAL::RESULT = regex("Here is a hidden value 47.11 inside", expression: ".*value ([0-9.]+) .*")

In this example we match a "string" that contains: "Here is a hidden value 47.11 inside". We want to extract the number value from this so our regex matches only numbers with a decimal point.

The resulting match of the regex is "47.11". This value is then stored in the variable RESULT in the LOCAL scope.

result: LOCAL::RESULT = regex("${-message}", expression: ".*value .*")

In this example, the "-" character is a string modifier that converts the entire string to lowercase. For more string modifiers go here .

result: LOCAL::MAJOR, result2: LOCAL::MINOR, result3: LOCAL::PATCH = regex("Version 4.7.0", "([0-9]+)\.([0-9]+)\.([0-9]+)")

In this example, a version number is extracted with a multi-submatch regex, so major, minor and patch numbers are extracted separately.

Case Insensitive Matching

In order to perform case-insensitive matching, you can either use the options argument or a regex literal with options:

# Using options argument
result: LOCAL::RESULT = regex("VaLuE: 42.0", expression: "value ([0-9.]+)", options: "i")
# Using regex literal
result: LOCAL::RESULT = regex("VaLuE: 42.0", expression: /value ([0-9.]+)/i)

# The options argument does not override the options of a regex
# literal, so this is has the same result as the last line:
result: LOCAL::RESULT = regex("VaLuE: 42.0", expression: /value ([0-9.]+)/i, options: "")