The Best Way to Use Regex? - Named Capture Groups in JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2023
  • 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:
    developer.mozilla.org/en-US/d...
    🏫 My Udemy Courses - www.udemy.com/user/domenic-co...
    🎨 Download my VS Code theme - marketplace.visualstudio.com/...
    💜 Join my Discord Server - / discord
    🐦 Find me on Twitter - / dcodeyt
    💸 Support me on Patreon - / dcode
    📰 Follow me on DEV Community - dev.to/dcodeyt
    📹 Join this channel to get access to perks - / @dcode-software
    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

ความคิดเห็น • 9

  • @karlstenator
    @karlstenator 8 หลายเดือนก่อน +1

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

  • @Sayvai
    @Sayvai 8 หลายเดือนก่อน +1

    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]" 🤓

  • @Seacrest.
    @Seacrest. 8 หลายเดือนก่อน +1

    thank you. This is a really convenient feature

  • @paulclarke4099
    @paulclarke4099 8 หลายเดือนก่อน +1

    Awesome, thanks 😄💯👍

  • @Dipenparmar12
    @Dipenparmar12 8 หลายเดือนก่อน

    Amazing tutorial Thanks.

  • @VforVanish
    @VforVanish 8 หลายเดือนก่อน

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

  • @KostaTsourdalakis
    @KostaTsourdalakis 8 หลายเดือนก่อน

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

    • @paulclarke4099
      @paulclarke4099 8 หลายเดือนก่อน

      Yes there is, just do a Google search for it, I think its just a standard RegEx feature so it should be available in almost any programming language 👍

  • @jay_wright_thats_right
    @jay_wright_thats_right 2 หลายเดือนก่อน

    LOL