Найти - Пользователи
Полная версия: Разделить с помощью split по всем спецсимволам.
Начало » Python для экспертов » Разделить с помощью split по всем спецсимволам.
1 2
py.user.next
Я тебе ссылку terabayt'а подравнял, так как для третьего информация полнее.
python.org. re

Вот инфа про вопросы
(?...)
This is an extension notation (a '?' following a '(' is not meaningful otherwise). The first character after the '?' determines what the meaning and further syntax of the construct is. Extensions usually do not create a new group; (?P<name>...) is the only exception to this rule. Following are the currently supported extensions.

Вот инфа про двоеточие
(?:...)
A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.

Вопросы означают расширения регулярных выражений. Двоеточие - это такое расширение, когда группа делается невидимой в результате. То есть совпадение с ней будет, но она не будет добавлена к результатам.

Вот пример, где используется расширение с двоеточием
  
>>> import re
>>> 
>>> match = re.search(r'(..)(..)(..)', 'abcdef')
>>> match.groups()
('ab', 'cd', 'ef')
>>> 
>>> match = re.search(r'(..)(?:..)(..)', 'abcdef')
>>> match.groups()
('ab', 'ef')
>>>
Первая группа нужна, вторая не нужна, третья нужна. Но чтобы вторую он не включал, хоть и совпал с ней, группа делается невидимой.
dobriy_dada
Спасибо :-)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB