Skip to content

Instantly share code, notes, and snippets.

@caok
Created July 24, 2013 01:30
Show Gist options
  • Save caok/6067486 to your computer and use it in GitHub Desktop.
Save caok/6067486 to your computer and use it in GitHub Desktop.
ruby 匹配 @ 艾特用户名的方法
# 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