indexof
Theindexof
filter returns the index of a string in another string.
indexof ("e" "hello) ≡ 1
If x
and y
are string filters, then indexof (x y)
has value the index (zero-based) of the first occurrence of the string represented by x
in the string represented by y
. If either argument does not match, or if x
does not occur in y
, then the filter fails to match. This filter does not use regular expressions:
x="pin"
y="mate"
indexof (y x+y) ≡ 3
indexof (y x) // fails to match
index of group captures
To get the index of a group capture expression like\1
within the target string it matched to,
use group capture index syntax, e.g. \-1
. Of course, you can still use
indexof
normally to find the location of \1
inside another string.
"pinmate"~~"mate" \-0 ≡ 3 "mate: 23" ~~ "mate: (\d+)" \-0 ≡ 0 \-1 ≡ 6 \1 in "1234" // matches the position