Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Last active May 20, 2020 07:28
Show Gist options
  • Save kurzweil777/67f8974896e08075c57445590cb0a76f to your computer and use it in GitHub Desktop.
Save kurzweil777/67f8974896e08075c57445590cb0a76f to your computer and use it in GitHub Desktop.
Regular Expressions
import re
# Задание: https://ibb.co/NKprbMW
number = ("42\n"
"1,234\n"
"6,368,745\n"
"12,34,567\n"
"1234")
numberRegex = re.compile(r'''^\d{1,3},\d{3},\d{3}|^\d{1,3},\d{3}|^\d{1,3}$''', re.MULTILINE)
result = numberRegex.findall(number)
print(result) # Получается ['42', '1,234', '6,368,745']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment