jquery,javascript用@更改文本链接 [英] jquery,javascript change text with @ to link
问题描述
我有这个字符串
@ [123:peterwateber] 你好!美好的一天!
我想将其更改为< a href =123> peterwateber< / a> &安培; LT; B和GT; hellow&安培;!LT; / B&安培; GT ;!美好的一天!
我想先做的,从给定的字符串开始,首先得到@ [123:peterwateber]将其转换为锚标记和带有htmlspecialchars的剩余字符串将被解析为纯文本。怎么做?
what I want to do first, from the given string, get first the @[123:peterwateber] convert it to an anchor tag and the remaining string with htmlspecialchars will be parsed to plain text. How to do this?
我用这段代码用PHP做了第一个: preg_match('#@ \ [(\\\ + +) \:(\ w +)\]#',$ hidden_input,$ m)
但这次我想在jquery或javascript中做...有什么建议吗?我非常需要你的帮助,它已经解决了这个问题3天:(
I did the first one using php by this code: preg_match('#@\[(\w+)\:(\w+)\]#', $hidden_input, $m)
but I wanna do it in jquery or javascript this time... any suggestions? I badly need your help guys its been 3 days solving this problem :(
推荐答案
正则表达式替换javascript
'@[123:peterwateber] hello! good day!'.replace(
/@\[(.*):(.*)\](.*)/,
'<a href="$1">$2</a>$3'
)
这篇关于jquery,javascript用@更改文本链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!