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
function hasNumber(myString) {
return /\d/.test(myString);
}
console.log(hasNumber("123 here12K there34 bla"));
returns true if the string has numbers in it.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.