[bb]Better string manipulation

This commit is contained in:
Jean-Marie Traissard 2007-03-31 12:07:40 +00:00
parent 83e3a2b4c9
commit e0b88bb53c
1 changed files with 4 additions and 10 deletions

View File

@ -1753,20 +1753,14 @@ class Interface:
# \S*[^\s\W] --> in the matching string don't match ? or ) etc.. if at the end # \S*[^\s\W] --> in the matching string don't match ? or ) etc.. if at the end
# so http://be) will match http://be and http://be)be) will match http://be)be # so http://be) will match http://be and http://be)be) will match http://be)be
prefixes = (r'http://', r'https://', r'gopher://', r'news://', r'ftp://', prefixes = '|'.join(('http://', 'https://', 'gopher://', 'news://',
r'ed2k://', r'irc://', r'magnet:', r'sip:', r'www\.', r'ftp\.') 'ftp://', 'ed2k://', 'irc://', 'magnet:', 'sip:', r'www\.',
r'ftp\.'))
# NOTE: it's ok to catch www.gr such stuff exist! # NOTE: it's ok to catch www.gr such stuff exist!
#FIXME: recognize xmpp: and treat it specially #FIXME: recognize xmpp: and treat it specially
prefix_pattern = '' links = r'\b(%s)\S*[\w\/\=]|' % prefixes
for prefix in prefixes:
prefix_pattern += prefix + '|'
prefix_pattern = prefix_pattern[:-1] # remove last |
prefix_pattern = '(' + prefix_pattern + ')'
links = r'\b' + prefix_pattern + r'\S*[\w\/\=]|'
#2nd one: at_least_one_char@at_least_one_char.at_least_one_char #2nd one: at_least_one_char@at_least_one_char.at_least_one_char
mail = r'\bmailto:\S*[^\s\W]|' r'\b\S+@\S+\.\S*[^\s\W]' mail = r'\bmailto:\S*[^\s\W]|' r'\b\S+@\S+\.\S*[^\s\W]'