mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
(wip) regex match op
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user