[英]How to remove all '#' symbols if they are at the start of word using javascript regular expression
I have a string and need to remove all '#' symbols, but only in case when they are placed at the beginning of the word. 我有一个字符串,需要删除所有的“#”符号,但前提是将它们放在单词的开头。 For example having next string:
例如,具有下一个字符串:
"#quick ##brown f#x"
Should be transformed into: 应转换为:
"quick brown f#x"
How it could be achieved using regular expressions in javascript? 使用javascript中的正则表达式如何实现? Thank you in advance for help
预先感谢您的帮助
var a = "#quick ##brown f#x"
var e = /(^| )#+/g
a.replace(e, "$1")
That should do the trick. 这应该够了吧。
You could either split the string and replace every hash #
sign that is at the beginning of the string. 你既可以分割字符串和替换每一个散列
#
标志是在字符串的开头。
var str = "#quick ##brown f#x", res = str.split(' ').map(v => v.replace(/^#+/, '')).join(' '); console.log(res);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.