# x: The int number
# n: Digit index
def digit_extraction_by_index(x, n):
return (abs(x) // (10 ** n)) % 10
print(digit_extraction_by_index(123, 0)) # 3
print(digit_extraction_by_index(123, 1)) # 2
import re
some_string = "Here is some text. We want to find matches in. Let's find the number 1234 and the number 5342 but not the number 942003. "
regex_pattern = re.compile(r"D(d{4})D")
matching_numbers = re.findall(regex_pattern, some_string)
print(matching_numbers)
'''
returns: 1234, 5342
'''
'''
The important part here is the `regex pattern`. Let's break it apart into 3 sections:
`r"<first><desired_match><last>"`
1. <first> is `D`
-> tells python that anything that isn't a digit, just ignore it.
2. <desired_match> is `(d{4})`
-> says that the pattern in `()` should be considered as a match.
3. <last> is `D`
-> tells python that anything that isn't a digit, just ignore it.
* Putting `d` would yeild all 3 sets of numbers `1234`, `5342`, and `942003`.
* `d{4}` is saying that the digits must be a at least 4 digits to match.
* The `<last>` portion prevents digits larger than 4.
'''
num = 123456
print(len(str(num)))