Coding

No need to get Frustrated | REGEX DEMYSTIFIED

  • 00:00:00 welcome to this video great to have you
  • 00:00:03 back on board I already created a couple
  • 00:00:05 of videos on regular expressions and
  • 00:00:08 I'll be very honest with you
  • 00:00:10 chances are it's still difficult to
  • 00:00:13 fully understand them now let me share
  • 00:00:15 my thoughts on this in this video
  • 00:00:20 so regular expressions are complex I
  • 00:00:24 created a couple of videos diving into
  • 00:00:26 some of its or self decor features we
  • 00:00:28 work with when working with regular
  • 00:00:31 expressions not all of them you can do
  • 00:00:33 way more and pages like regex 101 that
  • 00:00:36 come are great to learn more with the
  • 00:00:38 quick reference on the bottom right and
  • 00:00:40 the editor to test it the key thing
  • 00:00:42 about regular expressions is they are
  • 00:00:45 kind of hard to learn because it's very
  • 00:00:48 unintuitive how we we work with them or
  • 00:00:51 it's very different to how we otherwise
  • 00:00:53 write our code normally we write our
  • 00:00:57 code in English like language we have it
  • 00:01:01 very structured we have commands that we
  • 00:01:03 understand with regular expressions we
  • 00:01:06 put something very complex in one line
  • 00:01:09 in the end and we use just a limited set
  • 00:01:12 of commands it's not the problem that
  • 00:01:13 there would be too many commands the
  • 00:01:16 thing is it's very hard to see how these
  • 00:01:19 commands interact with Java how would I
  • 00:01:21 really build a pattern and I hope that
  • 00:01:24 my previous videos helped you a bit
  • 00:01:25 keeping in mind that you'll read it
  • 00:01:27 left-to-right that you can group things
  • 00:01:30 with parenthesis that you can define
  • 00:01:33 things like please take all characters
  • 00:01:35 that match this previous condition with
  • 00:01:37 the plus or with the star symbol these
  • 00:01:40 things still regular expressions can be
  • 00:01:43 tough and don't be frustrated if you
  • 00:01:46 still feel like I'm going to google them
  • 00:01:48 I also Google regular expressions if I
  • 00:01:52 want to find an email validation regular
  • 00:01:54 expression I google for it now the
  • 00:01:56 important part about googling is the
  • 00:01:59 following let's google for email regex
  • 00:02:02 if we do that if we google for email
  • 00:02:04 regex we'll find something like this
  • 00:02:07 Stack Overflow Fred here where people
  • 00:02:09 are discussing about the best possible
  • 00:02:11 regular expression for validating an
  • 00:02:14 email address in the client so with
  • 00:02:16 JavaScript let's say now we scroll down
  • 00:02:18 we find answer an answer which is marked
  • 00:02:21 as correct and now comes the important
  • 00:02:24 part about regular expressions if you
  • 00:02:26 google them which is absolutely fine
  • 00:02:27 everyone does that if someone tells you
  • 00:02:29 he never does Ted I wouldn't trust that
  • 00:02:32 person too much no seriously
  • 00:02:34 when Google said but if you google it
  • 00:02:36 read through the discussions you find if
  • 00:02:39 you scroll down in that discussion you
  • 00:02:41 find another answer which is not marked
  • 00:02:44 as the top answer but also uploaded
  • 00:02:46 quite a bit and there the person who
  • 00:02:50 created the answer actually gives a good
  • 00:02:52 explanation why you might look into
  • 00:02:54 different patterns and which one it
  • 00:02:56 recommends using and that is how you
  • 00:02:59 should approach to regular expressions
  • 00:03:00 you should be able to understand the the
  • 00:03:04 syntax in general you should understand
  • 00:03:07 yet that this part here simply creates a
  • 00:03:10 range where all special characters and a
  • 00:03:13 to said lowercase and numbers are
  • 00:03:16 allowed that's important this range
  • 00:03:18 wouldn't include Apple case characters
  • 00:03:20 though then that this plus here means it
  • 00:03:23 shouldn't just match one character from
  • 00:03:25 the range but all characters as long as
  • 00:03:28 this well as the subsequent characters
  • 00:03:30 are also in that range
  • 00:03:32 you should understand you should be able
  • 00:03:34 to read these regular expressions you
  • 00:03:36 can by the way always copy them in queue
  • 00:03:39 tools like read checks 101 and then have
  • 00:03:43 them parsed for you to understand and
  • 00:03:45 step by step here on the right so this
  • 00:03:48 is always an option now you can
  • 00:03:50 understand what this regular expression
  • 00:03:52 means and get some help and that is how
  • 00:03:55 I recommend working with them don't be
  • 00:03:57 frustrated
  • 00:03:58 Google them Google for the solutions you
  • 00:04:00 want but don't just blindly copy them
  • 00:04:02 analyze the solutions work with them
  • 00:04:04 read through discussions maybe try out
  • 00:04:08 your own solution first before you
  • 00:04:10 Google and then compare your solution
  • 00:04:12 with the best solution and that is how
  • 00:04:15 you can become better and how you can be
  • 00:04:17 confident that you use the best regular
  • 00:04:19 expression for a given shop now that may
  • 00:04:22 all sound trivial but I know that people
  • 00:04:25 forget these things were some parts of
  • 00:04:27 this process and especially always
  • 00:04:30 picking the first result you find isn't
  • 00:04:32 that great so this video on its own
  • 00:04:36 might have not taught you too many new
  • 00:04:38 things but maybe it did maybe taught you
  • 00:04:40 that you should carefully Google and
  • 00:04:42 that learning regular expressions really
  • 00:04:45 is about learning the commands
  • 00:04:47 practicing them still googling but then
  • 00:04:51 understanding what you found and at some
  • 00:04:53 point of time you'll be able to sketch
  • 00:04:55 out really good regular expressions on
  • 00:04:57 your own and you might only need to
  • 00:04:59 Google to validate them that is what I
  • 00:05:01 can give you because no regular
  • 00:05:04 expression tutorial can really teach you
  • 00:05:06 everything so that you leave it and say
  • 00:05:07 yeah I got it I understand it all I
  • 00:05:09 doubt that this is possible
  • 00:05:11 regular expressions are about practicing
  • 00:05:14 them and do you practice the most if you
  • 00:05:17 analyze existing expressions and then
  • 00:05:19 try it on your own
  • 00:05:20 so I hope this was helpful hopefully see
  • 00:05:22 you in future videos to have a great
  • 00:05:24 time bye