Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 25, 2020 12:15 am GMT

Step up your Regex game

Learning Regex (Regular Expressions) is not fun or easy at first, but it is a beyond important skill when strategizing solving problems with strings. Here is a brief overview on ways to best learn regex, tutorials on regex, and cheat sheets.

Alt Text

When I first saw Regex I immediately said what the heck is this!? I knew right off the bat it required some time and concentration to get it right and wrote it off as a Ill try this later kind of deal. I kept pushing it off and thought, hey Ill just code my way out of problems, no big deal. Was I ever wrong! In one of my most recent technical interviews, guess what? Regex came up!

Regex is very important, not only for solving problems that manipulate strings, but are widely used in text-editors, to search for data, filtering results, matching passwords, matching emails, validating forms, etc. You can go from solving a string manipulation problem on CodeWars or HackerRank in n time to cutting that time in half with Regex! This goes to show you how valuable Regex really is!

So began my process to understanding Regex completely. I dont want to strive to just solving problems by brute force, but rather Id like to be efficient as possible. Hence the quote, think smarter not harder.

Below I felt are the best ways to obtain that Regex knowledge, going from beginner to intermediate, and well advanced? If you want to be advanced you need to practice Regex on the reg, and if you set your mind to it you will achieve it.

First Steps:

You understand you need to learn Regex but where do you start??

Step 1 Take a tutorial:

Well praise God for DuckDuckGo (I only use DuckDuckGo) and Google, here are some pretty cool sites that offer a step-by-step learning process that will surely help. I like the fact that a few of these offer quizzes at the end.

  1. RegexOne https://regexone.com/
  2. Learn Regex https://learn-regex.com/
  3. RegularExpressions.Info Tutorial https://www.regular-expressions.info/tutorial.html
  4. Mozilla Regular Expressions (Use this to see how to code with Regex for beginners) https://www.regular-expressions.info/tutorial.html
  5. W3Schools JS Regex Tutorial https://www.w3schools.com/jsref/jsref_obj_regexp.asp
  6. Javascript.info Regular Expressions https://javascript.info/regular-expressions

Step 2 Practice on CodeWars or HackerRank:

Definitely start immediately on using Regex to solve problems when strings are present. The best place to do this is to go to CodeWars and HackerRank and start from the beginning. Whenever I start learning something new or need to refresh, I create a new account on these and start from the beginning and I always learn something new coding.

Another thing to note is it helps to solve these problems first on something familiar and helpful to you uniquely. I often create a new Repl.it and solve the problem there, then paste the solution in the HackerRank or CodeWars editor to solve. Just drag some of the arrays or data their using for the initial tests and run your solution on them. There are other online code editors such as JS Bin, PlayCode, or JS Fiddle that work great as well.

Here are a few sample problems that should be simple enough to use Regex on:

  1. CodeWars Your order, please: https://www.codewars.com/kata/your-order-please
  2. CodeWars Jaden Casing: https://www.codewars.com/kata/5390bac347d09b7da40006f6
  3. CodeWars Collection of Strings (problems involving strings)_: https://preview.codewars.com/collections/strings-130
  4. HackerRank Solve Regex (list of Regex Problems): https://www.hackerrank.com/domains/regex

Step 3 (optional) Find videos on YouTube, Udemy, or other sites:

If you want to be good at something and you need a visual kick or walk through just look up some videos to help follow along. This is just a suggestion and everyone has their own unique preference for people they like to follow along with. Get busy and do some searching!

Second Steps:

Youve learned the regex basics but where to go from here? Start your own projects immediately! The only way to really learn and commit those things to memory is straight up creating or building some projects yourself with 0 help from tutorials or anyone else. This is the only way to learn.

Here are some ideas for first projects:

  1. Create a Regex Matcher create a project where you can test a regex on a string, highlighting the exact matches on the string with the regex you provided. Give a simple Success! or Failed somewhere based on strings youre evaluating to match.
  2. Create a search filter bar: return only data sets that match the input given of a string. An example of this would be Netflix or DisneyPlus. Return only the videos that match or similar to what you are searching for in the search bar. There are a million ways to come up with your own version of this.

Useful Tools:

Keep practicing Regex. Here are some useful tools and cheat sheets to promote your growth!

Cheat Sheets:

Use these when referencing Regex on the go when using in your own projects and CodeWars or HackerRank:

  1. Regex Tutorial A quick cheat sheet by example by Johnny Fox: https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285
  2. Ultimate Regex Cheatsheet https://www.keycdn.com/support/regex-cheatsheet

Practicing your Regex:

Use these Regex engines to practice on. Will come in handy for writing out your Regex before you drop it into code when learning.

  1. Regexr.com https://regexr.com/
  2. Regex101.com https://regex101.com/

I hope you were able to get some value out of everything in this article. Just know that if you are struggling in programming or coding, there is always a solution and you can do it. No matter what never give up and keep growing. Everyone is unique, and the way you learn is to, you just have to make it fun and adapt to what works for you!

If you are someone who's worked with Regex before or have some knowledge on the subject, I have a few questions for you! What sites helped you grow/learn with Regex? What projects did you work on that helped as well? Please share below in the comments because I'd definitely like to know and I'm sure others would to!

Bless


Original Link: https://dev.to/blakecodez/step-up-your-regex-game-5689

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To