yq/pkg/yqlib/doc/String Operators.md

638 B

String Operators

Match string

Given a sample.yml file of:

cat

then

yq eval 'match("at")' sample.yml

will output

string: at
offset: 1
length: 2
captures: []

Match string, case insensitive

Given a sample.yml file of:

cAt

then

yq eval 'match("(?i)at")' sample.yml

will output

string: At
offset: 1
length: 2
captures: []

Match with capture groups

Given a sample.yml file of:

a cat

then

yq eval 'match("c(.t)")' sample.yml

will output

string: cat
offset: 2
length: 3
captures:
  - string: at
    offset: 3
    length: 2