简体   繁体   English

Javascript RegEx将所有单词提取为单个匹配项,但不从字符串中提取数字

[英]Javascript RegEx extract all words as single matches but not numbers from a string

How do I extract each single word, but not the number, from this string in Javascript RegEx? 如何从Javascript RegEx中的此字符串中提取每个单词,而不是数字?

"10443 Sometown Somesuburb" “ 10443 Sometown郊区”

I don't want the number but want "Sometown" and "Somsuburb" as separate matches. 我不想要数字,但希望将“ Sometown”和“ Somsuburb”作为单独的匹配项。

You can use this regex for your task: 您可以将此正则表达式用于您的任务:

/\b[a-zA-Z]+\b/g

to get only words containing letters for match function. 仅获取包含字母的单词以进行match功能。

尝试以下

var newStr = "10443 Sometown Somesuburb".replace(/\\d+\\s*/g, "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM