madisonmay / CommonRegex

A collection of common regular expressions bundled with an easy to use interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return position of matched text

piranna opened this issue · comments

Instead of returning an array of literals, return an array of objects of matched text and start position inside the original parsed text. Also, it would be good to have a list of all matched texts sorted by their position on the original text.

So this is currently supported, although indirectly. All compiled regexes are publicly exposed. To accomplish what you're looking for, you could do the following.

>>> from commonregex import time
>>> for m in time.finditer("Does 6:00 or 7:00 work better?"):
>>>     print m.start(), m.group()     
5 6:00 
13 7:00 

Hope that helps!

It's a posibility, maybe it should be added to the docs... :-)

Send from my Samsung Galaxy Note II
El 18/01/2014 16:48, "Madison May" notifications@github.com escribió:

So this is currently supported, although indirectly. All compiled regexes
are publicly exposed. To accomplish what you're looking for, you could do
the following.

from commonregex import time>>> for m in time.finditer("Does 6:00 or 7:00 work better?"):>>> print m.start(), m.group() 5 6:00 13 7:00

Hope that helps!


Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-32684809
.

Sure thing -- I'll update the docs to make sure everything is clear.