Syntax
/^(?<name>\p{L}+)=(?<count>\d+)$/uExamples
Named Captures and Unicode Regular Expressions: working example
Run this standalone example in a modern browser console unless another environment is specified. Expected result: The console prints café 13, then false.
const pattern = /^(?<name>\p{L}+)=(?<count>\d+)$/u;
const match = pattern.exec("café=12");
if (match) {
console.log(match.groups.name, Number(match.groups.count) + 1);
}
console.log(pattern.test("tea=-2"));- Expected result: The console prints café 13, then false.
- Named groups keep extraction readable when the pattern grows.
- The anchors require a complete match, and the unsigned decimal group rejects -2.
Best practices
- Check for a null match before reading captures.
- Define validation rules for the actual domain rather than assuming letters-only works for all names.
Runtime & versions
Browsers and JavaScript runtimes. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
ECMAScript specification