Skip to content

Commit f7ded0d

Browse files
committed
Update README.md
1 parent 2bdb6f7 commit f7ded0d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ regexp = expression.compile()
5454
result_re = regexp.sub('duck', replace_me)
5555
print result_re
5656
```
57+
### Using named groups
58+
```python
59+
name = "Linus Torvalds"
60+
expression = VerEx()
61+
.start_of_line()
62+
.word(name='first_name')
63+
.then(' ')
64+
.word(name='last_name')
65+
.end_of_line()
66+
.regex()
67+
match = self.exp.match(name)
68+
69+
print(match.group('first_name')) # Linus
70+
print(match.group('last_name')) # Torvalds
71+
```
5772
### Shorthand for string replace
5873
```python
5974
result = VerEx().find('red').replace('We have a red house', 'blue')

0 commit comments

Comments
 (0)