首页 > 解决方案 > Regular expression for capturing hashtags in groups

问题描述

I need a regular expression to capture a #hashtag in multiple groups(group 1-"#" group 2-"hasshtag"). I tried:

"(\\b#)([a-z0-9]{1,})(\\b)"

But this doesn't capture anything.Any suggestions?

标签: iosregex

解决方案


你可以使用这个正则表达式:

"(\\B#)([a-zA-Z0-9]+)"

\B断言\b不匹配的位置。使用\bbefore#将使匹配失败,除非 before 有单词字符#

正则表达式演示


推荐阅读