JavaScript regex, searching for hashtags

后端 未结 4 1062
醉话见心
醉话见心 2020-12-10 00:04

How can I search some text for any and all hashtags (alphanumeric AND underscore AND hyphen) and wrap them in span tags eg search

some_string = \"this is so         


        
4条回答
  •  情书的邮戳
    2020-12-10 00:42

    Try this replace call:

    EDIT: if you want to skip http://site.com/#tag kind of strings then use:

    var repl = some_string.replace(/(^|\W)(#[a-z\d][\w-]*)/ig, '$1$2');
    

提交回复
热议问题