(wip) regex match op

This commit is contained in:
Mike Farah
2021-07-09 14:58:31 +10:00
parent cc7ea83506
commit 573618e4ce
3 changed files with 44 additions and 64 deletions
+3 -36
View File
@@ -1,47 +1,13 @@
# String Operators
## Match string
Given a sample.yml file of:
```yaml
cat
```
then
```bash
yq eval 'match("at")' sample.yml
```
will output
```yaml
string: at
offset: 1
length: 2
captures: []
```
## Match string, case insensitive
Given a sample.yml file of:
```yaml
cAt
```
then
```bash
yq eval 'match("(?i)at")' sample.yml
```
will output
```yaml
string: At
offset: 1
length: 2
captures: []
```
## Match with capture groups
## Match with names capture groups
Given a sample.yml file of:
```yaml
a cat
```
then
```bash
yq eval 'match("c(.t)")' sample.yml
yq eval 'match("c(?P<cool>.t)")' sample.yml
```
will output
```yaml
@@ -52,5 +18,6 @@ captures:
- string: at
offset: 3
length: 2
name: cool
```