Created
July 24, 2013 01:30
-
-
Save caok/6067486 to your computer and use it in GitHub Desktop.
ruby 匹配 @ 艾特用户名的方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
#正则用于匹配用户名 | |
str = "@wikimo @中國 @水手 测试看看" | |
#{2,20}字符长度至少2个,不多于20个,以下任意方式匹配 | |
#arr = str.scan(/@([一-龠\w]{2,20}\s)/u).flatten | |
arr = str.scan(/@([\p{Han}+\w]{2,20}\s)/u).flatten | |
前端:https://github.com/ichord/jquery-atwho-rails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment