Javascript/jQuery - parse hashtags in a string using regex, except for anchors in URLs

后端 未结 3 971
我寻月下人不归
我寻月下人不归 2020-12-14 03:32

I\'ve looked at a couple of other possible solutions on SO but didn\'t see any that were doing what I was doing.

Currently I have been able to parse a string and det

3条回答
  •  离开以前
    2020-12-14 04:08

    I know this has been answered, but if you need styling, here's a solution i used on a project:

    The quick brown #fox jumps over the #second lazy dog
    //jquery var str = $('#result').html(); var edt = str.replace(/(^|\s)(#[a-z\d-]+)/ig, "$1$2"); $('#result2').html(edt); //CSS .hash_tag {color:red;} #result {display:none;}

提交回复
热议问题