Skip to content

Latest commit

 

History

History
18 lines (11 loc) · 556 Bytes

regex-named-groups.md

File metadata and controls

18 lines (11 loc) · 556 Bytes

Use named groups with regular expressions

In order to use named groups, we can add angled brackets in a regular expression like this:

const message = "Error 400: Your client has issued an illegal request";

const regex = /Error (?<code>\w+): (?<message>.*$)/;

const match = regex.exec(message);

console.log(match.groups.code);    // 400

console.log(match.groups.message); // Your client has issued an illegal request

References: