Hostmask matching

Nexu nexu.jin at gmail.com
Sun Jun 4 02:45:27 EDT 2006


On Sun, 2006-06-04 at 06:26 +0000, Marc Schoechlin wrote:
> Hi !
> 
> Nexu <nexu.jin at gmail.com> schrieb:
> > I'm trying to write a def to match a string that is an irc hostmask. eg:
> > *one!~*name at a??-??-101-101.someisp.com
> > But using re.search(). I get an error when the string starts with '*'.
> > What is the best way to solve this?
> 
> I suppose the problem occurs because you expression is not a valid
> regular expression.
> 
> A correct regular expression should look like this:
> ".*one!~.*name at a..-..-101-101.someisp.com"
Thx for everyones input.

This solved the problem:
	host = 'someone!~thename at a80-80-101-101.someisp.com'
	mask = '*one!~*name at a??-??-101-101.someisp.com'
	newmask = re.sub('\*', '.*', re.sub('\?', '.', mask))
result in that:
	re.search(newmask, host) == True





More information about the Python-list mailing list