Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Javascript中编写一个正则表达式,删除字符串中的第一个数字和后面的所有内容_Javascript_Regex - Fatal编程技术网

如何在Javascript中编写一个正则表达式,删除字符串中的第一个数字和后面的所有内容

如何在Javascript中编写一个正则表达式,删除字符串中的第一个数字和后面的所有内容,javascript,regex,Javascript,Regex,如何在Javascript中编写一个正则表达式来删除字符串中的第一个数字和后面的所有内容 例如: 约翰。Doe12@somewhere.net 到 John.Doe您可以像这样使用.replace(): var result = str.replace(/\d+.*$/, ""); 工作示例:谢谢。。。你知道关于学习编写正则表达式的好资源吗?@user1693131-正则表达式上有数百个很棒的网页。我建议您从谷歌搜索“javascript正则表达式”开始,然后选择最能显示您想知道的内容的页面。

如何在Javascript中编写一个正则表达式来删除字符串中的第一个数字和后面的所有内容

例如:

约翰。Doe12@somewhere.net

John.Doe

您可以像这样使用
.replace()

var result = str.replace(/\d+.*$/, "");

工作示例:

谢谢。。。你知道关于学习编写正则表达式的好资源吗?@user1693131-正则表达式上有数百个很棒的网页。我建议您从谷歌搜索“javascript正则表达式”开始,然后选择最能显示您想知道的内容的页面。@user1693131