Use regex.test() if all you want is a boolean result:

console.log(/^([a-z0-9]{5,})$/.test('abc1')); // false

console.log(/^([a-z0-9]{5,})$/.test('abc12')); // true

console.log(/^([a-z0-9]{5,})$/.test('abc123')); // true

...and you could remove the () from your regexp since you've no need for a capture.

Answer from user113716 on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-string-match
A Quick Guide to the String Match Method in JavaScript | DigitalOcean
January 7, 2020 - The string match() method will return an array with the items being matches from a provided regular expression found in the string.
🌐
W3Schools
w3schools.com › jsref › jsref_match.asp
W3Schools.com
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion · ❮ Previous JavaScript String Reference Next ❯ · A search for "ain" using a string: let text = "The rain in SPAIN stays mainly in the plain"; text.match("ain"); Try it Yourself » ·
Discussions

Check whether a string matches a regex in JS
The reason it works with a number is because the number is coerced into a string, because it's given as a parameter when it's expecting a string. I wouldn't rely on this behavior. It depends on your environment's implementation of test(). (match fails because numbers don't have a match member). More on stackoverflow.com
🌐 stackoverflow.com
How to use String.match() in javascript - Stack Overflow
I have this code here: Display the result here. ... More on stackoverflow.com
🌐 stackoverflow.com
Help please, JS regex: match everything after a string
Since JS doesn't support lookbehind or the singleline modifier, you'll have to use /([\s\S]*)/ then grab capture group 1. More on reddit.com
🌐 r/regex
5
2
December 6, 2015
Switch case statement with string matching for whole case

I'm not sure you understand how switch statements work.

switch(someVariable) {
case 'foo':
doSomething()
break
case 'bar':
doSomethingElse()
break
default:
break
}

The switch(someVariable) gets evaluated once. So if the value of someVariable was 'foo' then the first case would be run, if it was 'bar' then the second case. If it was something else, then it would fall back to the default case.

In your example, your switch statement is evaluating item. It does a comparison to the first case, which is a method invocation that returns a value (true/false), the method is invoked and the value that the switch is comparing to is either true or false. Since the value of item is probably not a boolean, then the case is false and it does not run the code block for it.

From the looks of it, you're better off using a simple if/else.

const jQuerySplit = data.data.split('.')
jQuerySplit.forEach((item, i) => {
if (item.match(/^\$\("[a-zA-z0-9]"\)$/g)) {
console.log('it works')
} else {
console.log('failed')
}
})
More on reddit.com
🌐 r/javascript
3
2
January 25, 2015
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › match
String.prototype.match() - JavaScript | MDN
const str1 = "All numbers except NaN satisfy <= Infinity and >= -Infinity in JavaScript."; const str2 = "My grandfather is 65 years old and My grandmother is 63 years old."; const str3 = "The contract was declared null and void."; str1.match("number"); // "number" is a string.
🌐
JavaScript.info
javascript.info › tutorial › regular expressions
Methods of RegExp and String
The method str.match(regexp) finds matches for regexp in the string str.
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-match-method-ce47295bfd97
Basics of Javascript · String · match() (method) | by Jakub Korch | Nerd For Tech | Medium
June 9, 2021 - The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › matchAll
String.prototype.matchAll() - JavaScript | MDN
July 10, 2025 - The matchAll() method of String values returns an iterator of all results matching this string against a regular expression, including capturing groups. const regexp = /t(e)(st(\d?))/g; const str = "test1test2"; const array = [...str.matchAll(regexp)]; console.log(array[0]); // Expected output: ...
🌐
CodingNomads
codingnomads.com › match-string-javascript
JavaScript String Matching
Learn string matching in JavaScript and how to use regex for complex patterns, from checking substrings to extracting emails.
🌐
Programiz
programiz.com › javascript › library › string › match
Javascript String match()
The match() method returns the result of matching a string against a regular expression.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript string match
JavaScript String Match
September 1, 2008 - The following is another example of the JavaScript match() method. Here, we use this method to search for the regular expression '/src/g' globally in the original string 'JavaScript is a scripting language' and try to retrieve an array with matches.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-match-method
JavaScript String match() Method - GeeksforGeeks
July 11, 2025 - JS Tutorial · Web Tutorial · ... · The match() method in JavaScript is used for identifying and retrieving substrings that fit a specified pattern, defined by a regular expression....
🌐
Medium
kelly-kh-woo.medium.com › js-101-regexp-exec-vs-string-match-2377102dd021
[JS-101] RegExp.exec vs String.match | by kelly woo | Medium
August 4, 2021 - [JS-101] RegExp.exec vs String.match Validation of form control is critical and most time we check the validity of the content and delete or fix certain characters with Regular …
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › match
JavaScript String Match() - Match String Pattern | Vultr Docs
November 15, 2024 - The match() method in JavaScript is used to retrieve the results of matching a string against a regular expression.
🌐
Codecademy
codecademy.com › docs › javascript › strings › .match()
JavaScript | Strings | .match() | Codecademy
June 11, 2025 - The .match() method searches a string for matches against a regular expression and returns the result as an array object. The .match() method is used in JavaScript to find parts of a string that match a regular expression.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String
String - JavaScript | MDN
Returns a number indicating whether the reference string compareString comes before, after, or is equivalent to the given string in sort order. ... Used to match regular expression regexp against a string.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript | MDN
js · const re = new RegExp("\\w+\\s", ... should be treated as multiple lines. If the m flag is used, ^ and $ match at the start or end of any line within the input string instead of the start or end of the entire string....
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns.
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
Jsremote
jsremote.jobs › tutorials › string-match
What is the match() method in JavaScript? | Web developer jobs
December 30, 2022 - This method accepts one parameter which is a regular expression specifying how the substring you are searching for should look like. The returned result would be an array containing the matches. In order to call this method you need to use your string of characters and a regular expression.