[OT] a little about regex

Fulvio fulvio at tm.net.my
Wed Oct 18 01:37:42 EDT 2006


***********************
Your mail has been scanned by InterScan MSS.
***********************


Hello,

I'm trying to get working an assertion which filter address from some domain 
but if it's prefixed by '.com'.
Even trying to put the result in a negate test I can't get the wanted result.

The tought in program term :

>>> def filter(adr):
...     import re
...     allow = re.compile('.*\.my(>|$)')
...     deny = re.compile('.*\.com\.my(>|$)')
...     cnt = 0
...     if deny.search(adr): cnt += 1
...     if allow.search(adr): cnt += 1
...     return cnt
...
>>> filter('some.ads at lazyfox.com.my')
2
>>> filter('some.ads at lazyfox.net.my')
1
>>>

Seem that I miss some better regex implementation to avoid that both of the 
filters taking action. I'm thinking of lookbehind (negative or positive) 
option, but I think I couldn't realize it yet.
I think the compilation should either allow have no '.com' before '.my' or 
deny should have _only_ '.com' before '.my'. Sorry I don't get the correct 
sintax to do it.

Suggestions are welcome.

F





More information about the Python-list mailing list