regular expression problem

Brian Oney brian.j.oney at googlemail.com
Sun Oct 28 18:57:48 EDT 2018


On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote:
> [^<:]

Would a simple regex work?

I mean:

~$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> t = '$<name::options::range>$'
>>> re.findall('[^<>:$]+', t)
['name', 'options', 'range']

You can then interpret what you have extracted afterwards.
Maybe if you want to have the single ones grouped you could consider:

>>> t = t*2
>>> t
'$<name::options::range>$$<name::options::range>$'
>>> re.findall('\$<+([^:]+)::([^:]+)::([^:]+)>+\$', t)
[('name', 'options', 'range'), ('name', 'options', 'range')]

HTH


More information about the Python-list mailing list