我正在尝试从传入值中删除特定文本
changeable:# this can be changeable
global:# this is global
manager:# this is manager
我想要的是:
this can be changeable
this is global
this is manager
如何将#
后的空格也删除
您可以使用替换方法
^
-字符串开头[^#]*
-匹配#
零个或多个时间以外的任何内容#
-匹配#
\s*
-匹配空格字符零个或多个时间let strArr = [`changeable:# this can be changeable`, `global:# this is global`, `manager:# this is manager`]
let textModifier = (str) => {
console.log(str.replace(/^[^#]*#\s*/, ''))
}
strArr.forEach(textModifier)