我正在尝试提取一个前面有一些常量字符串的字符串,示例如下。
string ="deleteabc@bcd"
match should be "abc@bcd"
or
string = "deletebcd@def"
match should be "bcd@def"
所以你可以看到我想在常量字符串“delete”之后提取任何内容, 请帮助,提前谢谢
答案 0 :(得分:2)
如果您只想删除前缀
function removePrefix(str, prefix) {
if (str.search(prefix) === 0) {
return str.substr(prefix.length);
} else {
return str;
}
}
答案 1 :(得分:2)
string = "deleteabc@bcd"
result = string.match(/^delete(.+)/)
console.log(result[1])
ABC @ BCD