Any match

2 snippets across 2 stacks - JavaScript, Regular Expressions

Also written as match any

JSJavaScript

includes(), some(), every()

JS · Arrays
Syntax
arr.includes(value)
arr.some(callback)
arr.every(callback)
Example
const perms = ["read", "write", "delete"];
console.log(perms.includes("write"));  // true

const ages = [22, 17, 30, 15];
console.log(ages.some(a => a < 18));   // true
console.log(ages.every(a => a >= 18)); // false

Note includes() uses strict equality (===) and works with NaN. some() short-circuits on the first true; every() short-circuits on the first false.

RXRegular Expressions

Dot (Any Character)

RX · Basic Patterns
Syntax
.  (matches any single character except newline)
Example
JS:  'bat bet bit'.match(/b.t/g)
Py:  re.findall(r'b.t', 'bat bet bit')
Output
["bat", "bet", "bit"]

Note The dot does NOT match newline (\n) by default. Use the s (dotall) flag to make dot match newline as well. A common beginner mistake is using . when you mean a literal period -- escape it as \. instead.

Frequently asked questions

How does JavaScript handle any match?
This task is covered in 2 stacks on this page: JavaScript, Regular Expressions. The "includes(), some(), every()" snippet in JavaScript uses `arr.includes(value)`.
Which code does the JavaScript example use?
The "includes(), some(), every()" snippet uses `arr.includes(value)`, from the Arrays section of the JavaScript cheat sheet.
Which stacks cover "any match" on this page?
JavaScript, Regular Expressions. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "includes(), some(), every()": includes() uses strict equality (===) and works with NaN. some() short-circuits on the first true; every() short-circuits on the first false.