常用的正则,有兴趣的可以参考下:
HTTP链接(例如http://www.weibo.com):
([hH]ttp[s]{0,1})://[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,4})(:\d+)?(/[a-zA-Z0-9\-~!@#$%^&*+?:_/=<>.',;]*)?
([hH]ttp[s]{0,1})://[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,4})(:\d+)?(/[a-zA-Z0-9\-~!@#$%^&*+?:_/=<>]*)?
(?i)https?://[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_\$\.\+!\*\(\)/,:;@&=\?~#%]*)*
^http?://[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(\/[\w-. \/\?%@&+=\u4e00-\u9fa5]*)?$
链接(例如www.baidu.com/s?wd=test ):
^[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_\$\.\+!\*\(\)/,:;@&=\?~#%]*)*
邮箱(例如sjobs@apple.com ):
\b([a-zA-Z0-9%_.+\-]{1,32})@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})\b
\b([a-zA-Z0-9%_.+\-]+)@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})\b
([a-zA-Z0-9%_.+\-]+)@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})
电话号码(例如18612345678):
^[1-9][0-9]{4,11}$
At (例如@王思聪):
@([\x{4e00}-\x{9fa5}A-Za-z0-9_\-]+)
话题(例如#奇葩说# ):
#([^@]+?)#
表情(例如[呵呵] ):
\[([^ \[]*?)]
匹配单个字符(中英文数字下划线连字符)
[\x{4e00}-\x{9fa5}A-Za-z0-9_\-]
匹配回复(例如回复@王思聪: ):
\x{56de}\x{590d}@([\x{4e00}-\x{9fa5}A-Za-z0-9_\-]+)(\x{0020}\x{7684}\x{8d5e})?: