正则表达式(javascript)提取前面有一些常量字符串的字符串

时间:2012-04-25 16:01:18

标签: javascript regex extract

我正在尝试提取一个前面有一些常量字符串的字符串,示例如下。

string ="deleteabc@bcd" 
match should be "abc@bcd"
or
string = "deletebcd@def"
match should be "bcd@def"

所以你可以看到我想在常量字符串“delete”之后提取任何内容, 请帮助,提前谢谢

2 个答案:

答案 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