EASILY The BEST Way To Do REGEX in JavaScript

preview_player
Показать описание
In today's video, I'll show you how to use named capturing groups to extract text from your regular expression matches. These work just like standard capturing groups, but allow you to name each section, making your code cleaner.

For your reference, check this out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

Legend - I did not know this. Can just tell it'll be most very useful!

karlstenator
Автор

Loving the video on named regex capture groups 🙌

💡If i were to further refactor the example regex pattern, I would also constrain the number of digits to just 1 or 2 digits for the hour and minutes portion of a time string, rather than loosely checking for one or more digits.

For example, with the current example regex of (\d+):(\d+) ?(am|pm), it would still match against this string "100:30 pm", as the hour portion satisfies the one or more digits constraint. But it would capture and produce the named group matches as "[100, 30, pm]".

And so by refactoring the regex to (\d{1, 2}):(\d{1, 2}) ?(am|pm), it would correctly not "fully" match against the above invalid time string, even if the hour (or minute) portion of the string exceeds 2 digits, but it would correctly capture and produce the named group matches as "[00, 30, pm]" 🤓

Sayvai
Автор

thank you. This is a really convenient feature

Seacrest.
Автор

can the positions of the array also be destructured or they can change in case a capture group doesnt find anything?

VforVanish
Автор

Hello sir this is a game changer, is there a similar feature in python? 😅

KostaTsourdalakis