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@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@f5ite ~/tests]$ [root@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
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor