On 4/06/2006 1:57 PM, Nexu wrote: > I'm trying to write a def Perhaps you mean a function?
> to match a string that is an irc hostmask. eg: > [EMAIL PROTECTED] > But using re.search(). If you want to find an IRC hostmask in some longer string, yes, use re.search(). However if you want to check that a given string could be an IRC hostmask, use re.match(). > I get an error when the string starts with '*'. Do you get an error when the searched string starts with anything else? > What is the best way to solve this? > A reasonable way would be to ask a question that includes the minimum useful information, so that would-be helpers are not forced to guess: 1. your inputs (the re pattern, and the searched string) 2. the expected outcome (match object that spans which part of the searched string) 3. the actual outcome (copy/paste of the traceback and error message that you got) Another way might be to Read The Fantastic Manual, in particular the section on re syntax, and nut out the answer your self. In any case, here's my guess as to what's going down: 1. You mean that the pattern starts with '*', not the searched string. 2. The error that you got was something like this: [snip] File "C:\Python24\lib\sre.py", line 180, in compile return _compile(pattern, flags) File "C:\Python24\lib\sre.py", line 227, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat 3. You haven't read this part of The Fantastic Manual: "\" Either escapes special characters (permitting you to match characters like "*", "?", and so forth), or ... === As well as TFManual, there's also a HOWTO: http://www.amk.ca/python/howto/regex/ HTH, John -- http://mail.python.org/mailman/listinfo/python-list