1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Better string sub documentation

This commit is contained in:
Mike Farah
2021-04-16 16:07:40 +10:00
parent 6c26344449
commit b2a538bdfc
3 changed files with 7 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ cat; meow; 1; ; true
## Substitute / Replace string
This uses golang regex, described [here](https://github.com/google/re2/wiki/Syntax)
Note the use of `|=` to run in context of the current string value.
Given a sample.yml file of:
```yaml
@@ -36,6 +37,7 @@ a: cats are great
## Substitute / Replace string with regex
This uses golang regex, described [here](https://github.com/google/re2/wiki/Syntax)
Note the use of `|=` to run in context of the current string value.
Given a sample.yml file of:
```yaml
@@ -44,7 +46,7 @@ b: heat
```
then
```bash
yq eval '.[] |= sub("([a])", "${1}r")' sample.yml
yq eval '.[] |= sub("(a)", "${1}r")' sample.yml
```
will output
```yaml