[Tutor] Question on re.findall usage
Dave Wilder
D.Wilder at F5.com
Mon Jan 28 20:15:24 CET 2013
Hello,
I am trying using re.findall to parse the string below and then create a list from the results.
junk_list = 'tmsh list net interface 1.3 media-ca \rpabilities\r\nnet interface 1.3 {\r\n media-capabilities {\r\n none\r\n auto\r\n 40000SR4-FD\r\n 10T-HD\r\n 100TX-FD\r\n 100TX-HD\r\n 1000T-FD\r\n 40000LR4-FD\r\n 1000T-HD\r\n }\r\n}\r\n'
What I am doing now is obviously quite ugly, but I have not yet able to manipulate it to work how I want but in a much more efficient and modular way.
I did some research on re.findall but am still confused as to how to do character repetition searches, which I guess is what I need to do here.
>> junk_list = re.findall(r'(auto|[1|4]0+[A-Z]-[HF]D|[1|4]0+[A-Z][A-Z]-[HF]D|[1|4]0+[A-Z][A-Z][0-9])', junk_list)
>> junk_list
['auto', '40000SR4', '10T-HD', '100TX-FD', '100TX-HD', '40000LR4', '1000T-FD', '1000T-HD']
>>>
Basically, all I need to search on is:
- auto
- anything that starts w/ '1' or '4' and then any number of subsequent zeroes e.g. 10T-HD, 40000LR4-FD, 100TX-FD
My environment:
[root at f5ite ~/tests]$ uname -a
Linux VM-QA-ITE-03 2.6.32-220.17.1.el6.i686 #1 SMP Tue May 15 22:09:39 BST 2012 i686 i686 i386 GNU/Linux
[root at f5ite ~/tests]$
[root at f5ite ~/tests]$ /usr/bin/python
Python 2.7 (r27:82500, Jul 6 2010, 02:54:50)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Any ideas?
Thanks,
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130128/4f27233e/attachment.html>
More information about the Tutor
mailing list