Найти - Пользователи
Полная версия: Regexp'ы. Небольшой вопрос
Начало » Python для новичков » Regexp'ы. Небольшой вопрос
1
dissdoc
Всем привет. Изучаю python. И наткнулся на такое регулярное выражение
(....\?P....)
Я впринципе знаю регулярки нормально. Но. Не пойму что значит символ Р
В PHP я помню, это связано с юникодом. В perle (по-моему!) обозначается как строчная, т.е. \?p
Но в python'е я не найду описания к этой команде. Я просто не найду в этом диалекте такого параметра… =\

З.Ы. про знак вопроса не надо пояснять ))) Это ноль или один )))
Андрей Светлов
(?P<name>…)
Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named. So the group named ‘id’ in the example above can also be referenced as the numbered group 1.
For example, if the pattern is (?P<id>\w*), the group can be referenced by its name in arguments to methods of match objects, such as m.group('id') or m.end('id'), and also by name in pattern text (for example, (?P=id)) and replacement text (such as \g<id>).

(?P=name)
Matches whatever text was matched by the earlier group named name.
dissdoc
ахаха… )) Теперь понятно. Я такого не видел, честно искал.
Тут все проще, как оказалось.
Т.е. имеется ввиду, что используется только с группами для разрешения узких мест.
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