Algoteka
Log in to submit your own samples!

Search with a Regex Pattern

Problem by oml1111
# Tech tags Title Creator Created date
1 0
2023-01-11 14:06
View all samples for this language (1 verified and 0 unverified)

Solution | Python |

By oml1111 |
0 likes

Matches using the standard re module

Code

import re
m = re.search(r'a=(\d+), b=(\d+)', 'Our coordinates are (a=123, b=5432), and we have some values too')
a = m.group(1)  # acquires value '123'
b = m.group(2)  # acquires value '5432'

Further reading

re: Regular expression operations - docs.python.org

References

functions
re.Match.group docs.python.org
re.search docs.python.org
classes
re.Match docs.python.org

Problem Description

Construct a regex pattern with some groups. Find a segment of some string that matches said pattern and fetch the parts that match the groups specified by the pattern.

View sample discussion (0 comments)
View problem discussion (0 comments)