正则表达式:单词开头的井号
我正在尝试查找以井号开头的单词。 JavaScript。
"test #word no#luck".replace( /\b#([\w]+)\b/g, "<#$1>" );
但单词边界似乎不适用于#符号。它输出:
test #word no<#luck>
我也有点困惑,我需要在替换模式“<#$1>”中再次添加 # 符号,因为算法似乎在此过程中将其剥离。
I am trying to find words starting with a pound sign. Javascript.
"test #word no#luck".replace( /\b#([\w]+)\b/g, "<#$1>" );
yet the word boundary doesn't seem to apply to the #-sign. it outputs:
test #word no<#luck>
also i am a bit confused that i need to add the #-sign again in the replacement pattern "<#$1>", as the algorithm seems to strip it in the process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是这样做的:
Here's how I'd do it:
试试这个:
\b
仅适用于\w
Try this:
\b
will only work with\w