我想保留一句话的一部分放在这样的函数的arg中:
var sen1 = "Hello this is my email"
var final = "this is my email"
我通常是Node.js和JS的初学者。我听说过RegExp函数,但是我不知道如何使用它从Hello
中删除sen1
。
任何人都可以帮助我或向我提出建议吗?
答案 0 :(得分:1)
您不需要RegEx,只需使用String方法replace()
。
语法如下:
"".replace(<What you want to replace>, <by what you want to replace it>)
所以您正在寻找:
let sen1 = "Hello this is my email"
let final = sen1.replace("Hello ", "");
console.log(final);
答案 1 :(得分:0)
您可以通过下面的RegEx进行操作。
var sen1 = "Hello this is my email"
console.log(sen1.replace(/^\w+\s/, ""));
RegEx的解释-^\w+\s
^
表示字符串的开头\w+
表示字符组(\w
)\s
表示空格