diff --git a/pkg/yqlib/doc/String Operators.md b/pkg/yqlib/doc/String Operators.md index e2abf3e6..b3fa0bdd 100644 --- a/pkg/yqlib/doc/String Operators.md +++ b/pkg/yqlib/doc/String Operators.md @@ -45,18 +45,18 @@ foo bar FOO ``` then ```bash -yq eval 'match("(?i)foo"; "g")' sample.yml +yq eval '[match("(?i)foo"; "g")]' sample.yml ``` will output ```yaml -string: foo -offset: 0 -length: 3 -captures: [] -string: FOO -offset: 8 -length: 3 -captures: [] +- string: foo + offset: 0 + length: 3 + captures: [] +- string: FOO + offset: 8 + length: 3 + captures: [] ``` ## Match with capture groups @@ -66,24 +66,24 @@ abc abc ``` then ```bash -yq eval 'match("(abc)+"; "g")' sample.yml +yq eval '[match("(abc)+"; "g")]' sample.yml ``` will output ```yaml -string: abc -offset: 0 -length: 3 -captures: - - string: abc - offset: 0 - length: 3 -string: abc -offset: 4 -length: 3 -captures: - - string: abc - offset: 4 - length: 3 +- string: abc + offset: 0 + length: 3 + captures: + - string: abc + offset: 0 + length: 3 +- string: abc + offset: 4 + length: 3 + captures: + - string: abc + offset: 4 + length: 3 ``` ## Match with named capture groups @@ -93,26 +93,26 @@ foo bar foo foo foo ``` then ```bash -yq eval 'match("foo (?Pbar)? foo"; "g")' sample.yml +yq eval '[match("foo (?Pbar)? foo"; "g")]' sample.yml ``` will output ```yaml -string: foo bar foo -offset: 0 -length: 11 -captures: - - string: bar - offset: 4 - length: 3 - name: bar123 -string: foo foo -offset: 12 -length: 8 -captures: - - string: null - offset: -1 - length: 0 - name: bar123 +- string: foo bar foo + offset: 0 + length: 11 + captures: + - string: bar + offset: 4 + length: 3 + name: bar123 +- string: foo foo + offset: 12 + length: 8 + captures: + - string: null + offset: -1 + length: 0 + name: bar123 ``` ## Capture named groups into a map @@ -154,18 +154,18 @@ cat cat ``` then ```bash -yq eval 'match("cat"; "g")' sample.yml +yq eval '[match("cat"; "g")]' sample.yml ``` will output ```yaml -string: cat -offset: 0 -length: 3 -captures: [] -string: cat -offset: 4 -length: 3 -captures: [] +- string: cat + offset: 0 + length: 3 + captures: [] +- string: cat + offset: 4 + length: 3 + captures: [] ``` ## Test using regex diff --git a/pkg/yqlib/operator_strings_test.go b/pkg/yqlib/operator_strings_test.go index ac7e8131..b7d80cd7 100644 --- a/pkg/yqlib/operator_strings_test.go +++ b/pkg/yqlib/operator_strings_test.go @@ -24,28 +24,25 @@ var stringsOperatorScenarios = []expressionScenario{ { description: "Match string, case insensitive", document: `foo bar FOO`, - expression: `match("(?i)foo"; "g")`, + expression: `[match("(?i)foo"; "g")]`, expected: []string{ - "D0, P[], ()::string: foo\noffset: 0\nlength: 3\ncaptures: []\n", - "D0, P[], ()::string: FOO\noffset: 8\nlength: 3\ncaptures: []\n", + "D0, P[], (!!seq)::- string: foo\n offset: 0\n length: 3\n captures: []\n- string: FOO\n offset: 8\n length: 3\n captures: []\n", }, }, { description: "Match with capture groups", document: `abc abc`, - expression: `match("(abc)+"; "g")`, + expression: `[match("(abc)+"; "g")]`, expected: []string{ - "D0, P[], ()::string: abc\noffset: 0\nlength: 3\ncaptures:\n - string: abc\n offset: 0\n length: 3\n", - "D0, P[], ()::string: abc\noffset: 4\nlength: 3\ncaptures:\n - string: abc\n offset: 4\n length: 3\n", + "D0, P[], (!!seq)::- string: abc\n offset: 0\n length: 3\n captures:\n - string: abc\n offset: 0\n length: 3\n- string: abc\n offset: 4\n length: 3\n captures:\n - string: abc\n offset: 4\n length: 3\n", }, }, { description: "Match with named capture groups", document: `foo bar foo foo foo`, - expression: `match("foo (?Pbar)? foo"; "g")`, + expression: `[match("foo (?Pbar)? foo"; "g")]`, expected: []string{ - "D0, P[], ()::string: foo bar foo\noffset: 0\nlength: 11\ncaptures:\n - string: bar\n offset: 4\n length: 3\n name: bar123\n", - "D0, P[], ()::string: foo foo\noffset: 12\nlength: 8\ncaptures:\n - string: null\n offset: -1\n length: 0\n name: bar123\n", + "D0, P[], (!!seq)::- string: foo bar foo\n offset: 0\n length: 11\n captures:\n - string: bar\n offset: 4\n length: 3\n name: bar123\n- string: foo foo\n offset: 12\n length: 8\n captures:\n - string: null\n offset: -1\n length: 0\n name: bar123\n", }, }, { @@ -76,10 +73,9 @@ var stringsOperatorScenarios = []expressionScenario{ { description: "Match with global flag", document: `cat cat`, - expression: `match("cat"; "g")`, + expression: `[match("cat"; "g")]`, expected: []string{ - "D0, P[], ()::string: cat\noffset: 0\nlength: 3\ncaptures: []\n", - "D0, P[], ()::string: cat\noffset: 4\nlength: 3\ncaptures: []\n", + "D0, P[], (!!seq)::- string: cat\n offset: 0\n length: 3\n captures: []\n- string: cat\n offset: 4\n length: 3\n captures: []\n", }, }, {