Created
August 4, 2021 05:48
-
-
Save xoxwgys56/6faeae94b5432ce1355a0eec9a9e9528 to your computer and use it in GitHub Desktop.
find digit group from text using re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
""" | |
find digit group from text | |
""" | |
def print_match(m): | |
print('\t',{ | |
'start':m.start(), | |
'group': m.group(), | |
'span': m.span(), | |
}) | |
include_digit_text = 'sr_pg_1_11a3222' | |
print(f'find digit from "{include_digit_text}"') | |
for m in re.finditer(r'[\d]+', include_digit_text): | |
print_match(m) | |
not_include_digit_text = 'sr_pg_' | |
print(f'find digit from "{not_include_digit_text}"') | |
for m in re.finditer(r'[\d]+', not_include_digit_text): | |
print_match(m) | |
print('finished.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result