JavaScript Tips — Named capturing groups in regular expressions

Опубликовано: 21 Ноябрь 2022
на канале: Code 2020
2,901
35

Named capturing groups in JavaScript regular expression let you assign easy to read names to the group. You can then use this name to look up the text the group matches

To name a capturing group, after the opening parenthesis of the group just add a ? followed by the name group surrounded buy angle brackets. Then on the match result, you can access the matched text using: match.groups.yourCapturingGroupName

This makes your regular expressions more resilient because extracting matches won't depend on the order or number of capturing groups. It also makes the code much easier to read because it is easy to tell which group is being accessed

https://developer.mozilla.org/en-US/d...


Смотрите видео JavaScript Tips — Named capturing groups in regular expressions онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Code 2020 21 Ноябрь 2022. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 2,901 раз и оно понравилось 35 посетителям.