python - regex find what's after slash without showing the slash -
i have script split informations in line, i've succeeded split , extract informations need have slash shows :/ i'de what's after here's example:
import re data = "12:05:12.121 o:class (sms:/xxx.xxx@xxx.xx) r:voice/1654354 mid:4312" ms = re.match(r'(\s+).*mid:(\d+)', data) # extract time , mid k = re.findall(r"/\s+", data ) # extract source , destination result = { 'time':ms.group(1), 'mid':ms.group(2), "source":k[0],"destination":k[1]} print result and here's result {'source': '/xxx.xxx@xxx.xx)', 'destination':'/1654354', 'mid':'4312','time':'12.05.12.121'}
and result want without slash here:
{'source': 'xxx.xxx@xxx.xx)', 'destination':'1654354', 'mid':'4312','time':'12.05.12.121'}
wrap \s+ in capturing group:
k = re.findall(r"/(\s+)", data) and here's way of getting info 1 regex:
import re data = "12:05:12.121 o:class (sms:/xxx.xxx@xxx.xx) r:voice/1654354 mid:4312" result = re.search(r''' (?p<time>.*?) \s+ .*? \s+ \( (?p<type>.*?):/(?p<source>.*?) \) \s+ .*/(?p<destination>\d+) \s+ mid:(?p<mid>\d+) ''', data, re.verbose) print result.groupdict()
Comments
Post a Comment