Zanurkuj w Pythonie/Analiza przypadku: Przetwarzanie numerów telefonów: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Linia 62:
>>>
 
# Teraz dopasowujemy początek łańcucha, grupę trzech cyfr, potem \D+... zaraz, zaraz, co to jest? \D dopasowuje dowolny znak, który nie jest cyfrą, a + oznacza "jeden lub więcej". Więc \D+ dopasowuje jeden lub więcej znaków nie będących cyfrą. Korzystamy z niego, aby dopasować różne separatory, nie tylko myślniki.
# Hang on to your hat. You're matching the beginning of the string, then a group of three digits, then \D+. What the heck is that? Well, \D matches any character except a numeric digit, and + means “1 or more”. So \D+ matches one or more characters that are not digits. This is what you're using instead of a literal hyphen, to try to match different separators.
# Korzystanie z \D+ zamiast - pozwala na dopasowywanie numerów telefonów ze spacjami w roli separatora części.
# Using \D+ instead of - means you can now match phone numbers where the parts are separated by spaces instead of hyphens.
# Oczywiście myślniki też działają.
# Of course, phone numbers separated by hyphens still work too.
# Niestety, to dalej nie jest ostateczna wersja, ponieważ nie obsługuje ona braku jakichkolwiek separatorów.
# Unfortunately, this is still not the final answer, because it assumes that there is a separator at all. What if the phone number is entered without any spaces or hyphens at all?
# No i dalej nie rozwiązany pozostał problem możliwości braku numeru wewnętrznego. Mamy więc dwa problemy do rozwiązania, ale w obu przypadkach rozwiążemy problem tą samą techniką.
# Oops! This still hasn't fixed the problem of requiring extensions. Now you have two problems, but you can solve both of them with the same technique.
 
Następny przykład pokazuje wyrażenie regularne pasujące także do numeru bez separatorów.
The next example shows the regular expression for handling phone numbers without separators.
 
'''Przykład 7.13. Obsługa numerów bez separatorów'''