3
I have a variable that can store several values (words, letters, numbers, etc.), depending on an input field. I would like to do a search that relates only 1 digit numbers (/ b d{1} b/), and any other information present in the "false" field as a result. Ex:
var test = "1";
console.log(test.match(/\b\d{1}\b/)); // corresponde e portanto é 'true'
var test = "sp 1 inf"; // mesmo assim corresponde com "test.match(/\b\d{1}\b/)"
What I want is a modification in "test.match(/ b d{1} b/)" that gives "false" as a result in the second case (var test = "1 info"), therefore, not corresponding. Thanks for your attention.
In other words, you want regex to marry only if the entire string case, not part of it, is this?
– mgibsonbr
By the way, to marry a single digit you don’t need to
\d{1}
, only\d
that’s enough...– mgibsonbr