Develop Flawless Regular Expressions Using This Step-by-Step Process

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ต.ค. 2024
  • Become a patron and download the source code: / zoranhorvat
    Do you feel like you have a fair understanding of regular expressions and yet you always struggle to apply what you know?
    Do you search the internet for regular expressions you need, only to find that everything you've got is either wrong, incomplete or not appropriate for the problem you're solving?
    In this video, I will show you a step-by-step process that will help you develop regular expressions of whatever complexity you need.
    If you follow these steps every time, your regular expressions will always be correct and appropriate for the problem you are solving.
    Thank you so much for watching! Please like, comment & share this video as it helps me a ton!! Don't forget to subscribe to my channel for more amazing videos and make sure to hit the bell icon to never miss any updates.🔥❤️
    ✅🔔 Become a patron ► / zoranhorvat
    ✅🔔 Subscribe ► / @zoran-horvat
    ⭐ Learn more from video courses:
    Beginning Object-oriented Programming with C# ► codinghelmet.c...
    ⭐ Collections and Generics in C# ► codinghelmet.c...
    ⭐ Making Your C# Code More Object-oriented ► codinghelmet.c...
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⭐ CONNECT WITH ME 📱👨
    🌐Become a patron ► / zoranhorvat
    🌐Buy me a Coffee ► ko-fi.com/zora...
    🗳 Pluralsight Courses ► codinghelmet.c...
    📸 Udemy Courses ► codinghelmet.c...
    📸 Join me on Twitter ► / zoranh75
    🌐 Read my Articles ► codinghelmet.c...
    📸 Join me on LinkedIn ► / zoran-horvat
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    👨 About Me 👨
    Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my TH-cam channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⚡️RIGHT NOTICE:
    The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
    ⭐For copyright or any inquiries, please contact us at zh@codinghelmet.com
    #csharp #dotnet #regularexpressions

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

  • @zoran-horvat
    @zoran-horvat  ปีที่แล้ว +2

    Enroll video course *Beginning Object-Oriented Programming with C#* ► codinghelmet.com/go/beginning-oop-with-csharp
    Download the source code: www.patreon.com/ZoranHorvat
    Learn from related videos:
    Avoid Returning Null From Methods - There Is a Better Way To Write Them! ► th-cam.com/video/HRLdcMil7Ec/w-d-xo.html
    Clean Code Tip: Remove Messy Constructor Calls ► th-cam.com/video/6g4ggpOxxCc/w-d-xo.html
    Use the Decorator Pattern To Reduce Code Duplication in Complex Models ► th-cam.com/video/7N0LpGAI5T4/w-d-xo.html

  • @phyberoptyk5619
    @phyberoptyk5619 ปีที่แล้ว +4

    Thanks Zoran. Whenever I get the feeling that my hubris about my coding ability is getting too much I just attempt to write a regex by hand. It is a most humbling experience.

  • @superpcstation
    @superpcstation ปีที่แล้ว +7

    I'm in awe of your masterful abilities

  • @nickbarton3191
    @nickbarton3191 ปีที่แล้ว +4

    Learnt two things (well three). Didn't know about pipe for alternative matching, didn't know about group names, very useful. The third ? Isolation of the match into a class SRP.
    Very helpful.

  • @adambickford8720
    @adambickford8720 ปีที่แล้ว +4

    When you solve a problem with a regex, you now have 2 problems!
    Kidding aside, great video on tacking a tricky problem by iterating on it and building it up. Once you get good enough even you can't explain the total solution without rederiving it!

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +1

      In a way, you are right or, as it is often said, there is a grain of truth in every joke.
      The trouble would be if someone believed the joke entirely. We reach out to regular expressions when the data are complex. In the least when common search and replace doesn't apply because the search pattern would vary along the data.
      The worst thing that can happen is someone parsing the complex data using other means because of the fear or lack of knowledge of regexes. The resulting code would be far worse than a regex, I guess.

  • @Bankoru
    @Bankoru ปีที่แล้ว +1

    As a mathematician, regex came naturally to me, I imagine there are several parallels if that's the case.

  • @DongoBongKong
    @DongoBongKong ปีที่แล้ว +2

    Regex are so tricky. Sometimes it makes my had feel like a giant boiling headache. As developers we should be proficient in and have a basic understanding of regex, but the question is whether our scarce time is spent better on learning more urgent topics. It all of course depends on the type of work we are doing. But it can also be said regex is a very stable skill that changes little over time contrary to the big churn we see in framework development, so learning them well might actually pay

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว

      Serialization libraries of all kinds have removed regex from our sight. Still, it is an essential and indispensable skill when working with raw data.
      The problem with programmers who are not proficient in regex is that they often seek subpar solutions to their immediate problems, where regex is *the* solution to processing and transforming raw strings with complex structure.

  • @marklord7614
    @marklord7614 ปีที่แล้ว

    I would have liked to hear more of the thought process behind your approach to constructing the regular expression. You started by stating that you would start with any idea but you never stated why you thought matching only commas to start was the way to go. I think it would have been valuable to see your approach to solving the problem before you knew the solution.

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +1

      The data consisted of several cases: Plain text, text with a comma, text with a double quote, an empty cell. I was developing the regular expression to cover each of those categories, in order of their appearance in the test data.
      An added requirement is that, once a certain number of cells from the beginning of the row have been matched, any subsequent change to the regex must not ruin that. That is the reason why I was mostly adding to the regular expression, and paying close attention in situations when I was changing a part of the expression.

    • @marklord7614
      @marklord7614 ปีที่แล้ว

      @@zoran-horvat Thanks for the clarification. One other question. The typical approach to solving regular expressions is left to right starting with the leftmost item. However, you chose to start with not matching commas [^,]*. You implied that you were just playing around, but then built the remaining regular expression from that starting point? This seemed intentional. What was your reasoning for starting this way rather than matching "one" and then dealing with the commas in order.

  • @asap8426
    @asap8426 ปีที่แล้ว

    What I'd never do if I can help it: number value checks in regex - it's getting messy quite fast.
    Extract the numbers, try to parse them and then do a check up on the value. Easy win. ;)

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +1

      That is true when the number is an isolated value. When it is a part of a larger structure, then that method would not apply.

  • @_NguyenManhToan_
    @_NguyenManhToan_ ปีที่แล้ว +1

    ❤❤❤❤❤❤❤❤❤❤❤❤

  • @bloopers2967
    @bloopers2967 ปีที่แล้ว

    Once again, i didn't understand it. Guess I'm just too noob

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว +1

      Try the same exercise yourself on that site. There is no better way to learn regex than to practice it.

    • @bloopers2967
      @bloopers2967 ปีที่แล้ว

      @@zoran-horvat yea thank you

  • @serus164
    @serus164 ปีที่แล้ว

    Or you could give up the hustle and let chat gpt write it for you effortlessly

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว

      Did you try it? I'll give you a hint: it produces the wrong result.
      And the bonus lesson: If you "give up the hassle" you might not even know what's wrong.

    • @serus164
      @serus164 ปีที่แล้ว

      @@zoran-horvat did you try the gpt4 version? In most cases it produced desired results with explanation and step-by-step guide.

    • @zoran-horvat
      @zoran-horvat  ปีที่แล้ว

      @@serus164 First of all, if you want a correct expression, then you need the correct data, with all the special cases included. The erroneous expressions produced by GPT usually come from underdefining the problem, like leaving it to the AI to figure out what you thought. That just doesn't work.
      Preparing the data is 90% of work with any regular expression. Writing the expression itself is the smallest part of work.
      Don't forget that naming the groups - which is usually mandatory in any data processing - requires to be explained to GPT up front as well.
      Under the line, I would say that developing a regex using GPT would take 50-100% more time and effort than doing it yourself.
      And a friendly note: Knowing regular expressions is not a hassle. It is expert knowledge. You don't have to be disrespectful to expertise.

    • @Bankoru
      @Bankoru ปีที่แล้ว +1

      I have to constantly fight against ChatGPT results because it is just plain wrong often.