Try it free

DPL Positional Matchers

  • Latest Dynatrace
  • Reference

Positional matchers are zero-width matchers that constrain where a pattern can match within the input. They produce no captured value and must be combined with other matchers such as LD, WORD, or IPADDR.

Positional matchers always refer to the absolute start or end of the input string, regardless of newlines. Use EOL to match line boundaries.

matchesPattern anchors the pattern to the entire input, so positional matchers like BOS and EOS are redundant here—the function already requires a full-input match. This is why the patterns on this page can often appear to work the same with or without the positional matcher. Their effect becomes relevant with functions that can match anywhere in the input, such as parseAll, where the position constraint is what limits where the pattern is allowed to match.

BOS, BOF

BOS (beginning of string) and BOF (beginning of file) match the position at the very start of the input.

Returns

BOS and BOF produce no output. They are positional anchors that constrain matching to the start of the input.

Basic examples

Example 1: Match input that starts with INFO:

Use the following expression to check whether the input starts with INFO::

BOS 'INFO:' LD
Descriptioninput (string)result (boolean)

Starts with INFO:

INFO: server started

true

Starts with DEBUG:

DEBUG: handler invoked

false

INFO: appears mid-string

Log entry - INFO: started

false

See how to use in DQL
data record(input = "INFO: server started"),
record(input = "DEBUG: handler invoked"),
record(input = "Log entry - INFO: started")
| fieldsAdd result = matchesPattern(input, "BOS 'INFO:' LD")
Example 2: Parse the header line from a multi-line CSV string

Given the following input:

input (string)
"name","surname"
"Ned","Flanders"
"Homer","Simpson"
"Charles","Burns"

Use the following expression to extract the first line:

BOS LD:header
header (string)

"name","surname"

See how to use in DQL
data record(input = """"name","surname"
"Ned","Flanders"
"Homer","Simpson"
"Charles","Burns"""")
| parse input, "BOS LD:header"

MOS, MOF

MOS (middle of string) and MOF (middle of file) match any position that is neither the start nor the end of the input. Because parse and matchesPattern work on the input as a whole, MOS is mainly used inside iterative matching with the parseAll function, where it restricts matches to positions other than the very start.

Returns

MOS and MOF produce no output. They are positional anchors that exclude matches at the start or end of the input.

Basic examples

Example 1: Match ERROR in the middle of the input

Use the following expression to check whether ERROR appears in the middle of the input—neither at the start nor at the end:

LD MOS 'ERROR' MOS LD
Descriptioninput (string)result (boolean)

ERROR in the middle

Got ERROR while parsing

true

ERROR at the very start

ERROR while parsing

false

ERROR at the very end

Failed with ERROR

false

No ERROR present

Operation succeeded

false

See how to use in DQL
data record(input = "Got ERROR while parsing"),
record(input = "ERROR while parsing"),
record(input = "Failed with ERROR"),
record(input = "Operation succeeded")
| fieldsAdd result = matchesPattern(input, "LD MOS 'ERROR' MOS LD")
Example 2: Parse all data rows from a multi-line CSV string

Given the following input:

input (string)
"name","surname"
"Ned","Flanders"
"Homer","Simpson"
"Charles","Burns"

Use the following expression with parseAll to extract every line except the first one. MOS ensures the header line at position 0 is skipped:

MOS DQS:name ',' DQS:surname (EOL | EOS)
name (string)surname (string)

Ned

Flanders

Homer

Simpson

Charles

Burns

See how to use in DQL
data record(input = """"name","surname"
"Ned","Flanders"
"Homer","Simpson"
"Charles","Burns"""")
| fields rows = parseAll(input, "MOS DQS:name ',' DQS:surname (EOL | EOS)")

EOS, EOF

EOS (end of string) and EOF (end of file) match the position at the very end of the input. Use EOS with parse to require the matched portion to extend to the input's last character—without EOS, parse succeeds even when extra content follows the match. In matchesPattern, end-anchoring is implicit, so EOS is most useful with parse or inside alternations.

Returns

EOS and EOF produce no output. They are positional anchors that constrain matching to the end of the input.

Basic examples

Example 1: Match input that ends with OK

Use the following expression to check whether the input ends with OK:

LD 'OK' EOS
Descriptioninput (string)result (boolean)

Ends with OK

Status: OK

true

Ends with a different word

Status: failed

false

OK at the start

OK then failed

false

See how to use in DQL
data record(input = "Status: OK"),
record(input = "Status: failed"),
record(input = "OK then failed")
| fieldsAdd result = matchesPattern(input, "LD 'OK' EOS")
Example 2: Match an IP address at the end of the record

Use the following expression to check whether each record ends with an IP address. The expression matches only when no content follows the IP:

LD IPADDR EOS
input (string)result (boolean)

userId=1246 ip=124.5.2.4

true

userId=441122 ip=75.52.12.1 status=error message='Login failed'

false

userId=753434 ip=4.4.3.2

true

See how to use in DQL
data record(input = "userId=1246 ip=124.5.2.4"),
record(input = "userId=441122 ip=75.52.12.1 status=error message='Login failed'"),
record(input = "userId=753434 ip=4.4.3.2")
| fieldsAdd result = matchesPattern(input, "LD IPADDR EOS")
Example 3: Parse an IP address with and without EOS

Given the following input, which contains two IP addresses:

Log has 127.0.0.1 and ends with 156.34.11.23

Without EOS, the expression extracts the first IP found anywhere in the input:

LD IP:out
out (ip)

127.0.0.1

See how to use in DQL
data record(input = "Log has 127.0.0.1 and ends with 156.34.11.23")
| parse input, "LD IP:out"

With EOS, the expression extracts an IP only when it is the last value in the input:

LD (IP:out EOS)
out (ip)

156.34.11.23

See how to use in DQL
data record(input = "Log has 127.0.0.1 and ends with 156.34.11.23")
| parse input, "LD (IP:out EOS)"
Related tags
Dynatrace Platform