PDA

View Full Version : Regular expressions in Python



Duh
01-19-2010, 12:12 PM
As posted on another forum (WHT) :


Hi, I would like to know which would be the appropriate code (using regular expressions) to find a proxy address which is ''floating'' in a web site.
I found a synonym in Perl.



the RE ( regular expression ) I found is in perl, any idea of a similar but for python? Mine does not contemplate the second part of a proxy address ( the '':'' and the part number)

many thanks in advance

ahmad
01-19-2010, 12:46 PM
Regular expressions are language independent. If one works in perl it must work in python.

Duh
01-19-2010, 02:47 PM
thanks, it helped me clear out, mate! Fact is that I still need the : and the port number

ahmad
01-20-2010, 11:25 AM
This:


\b(?:\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?\b

should work.

Without making it overly long and confusing, it will easily match 0.0.0.0 all the way to 999.999.999.999:99999. More specific is possible obviously but disgusting.

This

http://www.regexplanet.com/simple/index.html

is fun for playing with regexs.

Duh
01-20-2010, 02:23 PM
Nice one mate, many thanks!

Duh
03-13-2010, 10:26 PM
This:


\b(?:\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?\b

should work.

Without making it overly long and confusing, it will easily match 0.0.0.0 all the way to 999.999.999.999:99999. More specific is possible obviously but disgusting.

This

http://www.regexplanet.com/simple/index.html

is fun for playing with regexs.


Sorry for the thread revival but this regex does not fit this particular proxy for instance.

Thanks

116.49.95.13:808