Reputation: 632
I have found the following regular expression, and I don't understand what does that mean? I need help to understand that. Specially 'p' in middle of everything:
RE_CALLEE = re.compile(r'(?P<callee>\+[0-9]+)')
This is an example of code:
2015-11-01T00:00:17.735616+00:00 x1ee energysrvpol[15690]: INFO consume_processor: user:<<"dbdiayhg">> callee_num:<<"+1288888888">> sid:<<"A1003unjhjhvhgfgvhbghgujhj02">> credits:-0.5000000000000001 result:ok provider:ooioutisrt.ym.ms
Upvotes: 0
Views: 80
Reputation: 474003
(?P<callee>)
part is a named capturing group\+[0-9]+
would match a plus character followed by one or more digitsHere is how you can get the group by it's name:
>>> import re
>>> RE_CALLEE = re.compile(r'(?P<callee>\+[0-9]+)')
>>>
>>> RE_CALLEE.search("test +10").group("callee")
'+10'
As for your example, how about this pattern:
>>> RE_CALLEE = re.compile(r'callee_num:<<"(\+\d+)"')
>>> RE_CALLEE.findall(s)
['+1288888888']
Upvotes: 2