简体   繁体   English

如何提取与数字正则表达式混合的单词

[英]how to extract words mixed with numbers regex

I have a string containing a word that is sometimes mixed with numbers, I try to check if there is a particular word in this string, so I tried to do something like this: Original string:我有一个包含有时与数字混合的单词的字符串,我尝试检查此字符串中是否有特定的单词,因此我尝试执行以下操作:原始字符串:

str="123 here12K there34 bla"

regex:正则表达式:

RegExp(\'here'\d*+[A-Z]?).test(str)

and always get not available.并且总是不可用。 I found this: similar question but still the same result我发现了这个: 类似的问题,但结果仍然相同

var txt = "#div-name-1234-characteristic:561613213213";
var numb = txt.match(/\d/g);
numb = numb.join("");
alert (numb);​

This might help you.这可能对你有帮助。

Edit 1编辑 1

function hasNumber(myString) {
  return /\d/.test(myString);
}
console.log(hasNumber("123 here12K there34 bla"));

returns true if the string has numbers in it.如果字符串中有数字,则返回 true。

Your question is not really clear for a regexp question ...对于正则表达式问题,您的问题并不是很清楚......

But based on what you're saying :但根据你所说的:

/\\bhere\\d+?\\b/g

will match any 'here' word that could have numbers after it将匹配任何后面可能有数字的“此处”字词

Check this fiddle to see if it's OK to you ... If not, please share all text-cases needed to solve your problem by providing a regexp101 link检查这个小提琴,看看你是否可以......如果不是,请通过提供 regexp101 链接分享解决您的问题所需的所有文本案例

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

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