From 897604142f92c9e9947567a5c3cb754052d42a66 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 23 Mar 2022 10:28:45 +1100 Subject: [PATCH] Better string docs --- pkg/yqlib/doc/operators/headers/string-operators.md | 11 +++++++++++ pkg/yqlib/doc/operators/string-operators.md | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/yqlib/doc/operators/headers/string-operators.md b/pkg/yqlib/doc/operators/headers/string-operators.md index 02979475..d1940544 100644 --- a/pkg/yqlib/doc/operators/headers/string-operators.md +++ b/pkg/yqlib/doc/operators/headers/string-operators.md @@ -3,6 +3,17 @@ ## RegEx This uses golangs native regex functions under the hood - See https://github.com/google/re2/wiki/Syntax for the supported syntax. +### match(regEx) +This operator returns the substring match details of the given regEx. + +### capture(regEx) +Capture returns named RegEx capture groups in a map. Can be more convenient than `match` depending on what you are doing. + +# test(regEx) +Returns true if the string matches the RegEx, false otherwise. + +## sub(regEx, replacement) +Substitutes matched substrings. The first parameter is the regEx to match substrings within the original string. The second is a what to replace those matches with. This can refer to capture groups from the first RegEx. ## String blocks, bash and newlines Bash is notorious for chomping on precious trailing newline characters, making it tricky to set strings with newlines properly. In particular, the `$( exp )` _will trim trailing newlines_. diff --git a/pkg/yqlib/doc/operators/string-operators.md b/pkg/yqlib/doc/operators/string-operators.md index 47c3e320..a65fae0c 100644 --- a/pkg/yqlib/doc/operators/string-operators.md +++ b/pkg/yqlib/doc/operators/string-operators.md @@ -3,6 +3,17 @@ ## RegEx This uses golangs native regex functions under the hood - See https://github.com/google/re2/wiki/Syntax for the supported syntax. +### match(regEx) +This operator returns the substring match details of the given regEx. + +### capture(regEx) +Capture returns named RegEx capture groups in a map. Can be more convenient than `match` depending on what you are doing. + +# test(regEx) +Returns true if the string matches the RegEx, false otherwise. + +## sub(regEx, replacement) +Substitutes matched substrings. The first parameter is the regEx to match substrings within the original string. The second is a what to replace those matches with. This can refer to capture groups from the first RegEx. ## String blocks, bash and newlines Bash is notorious for chomping on precious trailing newline characters, making it tricky to set strings with newlines properly. In particular, the `$( exp )` _will trim trailing newlines_.