Last active
November 6, 2022 06:07
-
-
Save DarkCat09/70c6ed86086e5f3ad08f7b2f76c72527 to your computer and use it in GitHub Desktop.
Just compare RegExp and Python code
This file contains hidden or 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
# s = какая-то строка | |
# например: | |
s = 'q 1' | |
match = 0 | |
while match != -1: | |
# ищем два пробела | |
# начиная с пред. индекса, | |
# т.е. match, 2-ой аргумент | |
match = s.find(' ', match) | |
# -1 = не найдено | |
if match == -1: | |
break | |
# сохраняем индекс пробелов | |
spaces = match | |
# пропускаем эти пробелы | |
match += 2 | |
for sym in s[match:]: | |
# если опять | |
# встретили пробел | |
if sym == ' ': | |
match += 1 | |
continue | |
# иначе | |
break | |
# проверяем, | |
# что не достигли | |
# конца строки | |
if match >= len(s): | |
print('No match') | |
break | |
# второе условие задачи | |
next_sym = s[match] | |
upper = next_sym.isupper() | |
is_a = next_sym == 'A' | |
digit = next_sym.isdigit() | |
if (upper and not is_a) or digit: | |
print('Found') | |
else: | |
# продолжаем while | |
continue | |
# если таки continue | |
# не случился, | |
# показываем символ | |
# перед пробелами | |
prev_sym = '' | |
try: | |
prev_sym = s[spaces - 1] | |
except IndexError: | |
# нет символа? | |
# не проблема, в группе | |
# будет пустая строка | |
pass | |
print('Group 1:', prev_sym) | |
print() |
This file contains hidden or 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
(.?)\x20{2,}(?=[B-Z0-9]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment