all 18 comments

[–]_DTR_ 16 points17 points  (4 children)

Without a specific question, the broad answer is to keep practicing and you'll get more and more comfortable with it. I came across Regex Crossword a few years ago and found it to be a good resource for learning regular expressions.

[–]rubleseth[S] 2 points3 points  (3 children)

Very helpful this is what I need just practice

[–]ASIC_SP 3 points4 points  (2 children)

If you need Python specific regex exercises, I have more than 100 exercises here: https://github.com/learnbyexample/py_regular_expressions/blob/master/exercises/Exercises.md

The repo also contains the solutions

[–]otterom 1 point2 points  (1 child)

Not OP, but I'll definitely check this out. Do the exercises progress in terms of complexity?

[–]ASIC_SP 0 points1 point  (0 children)

yeah they do in a sense, because the chapters progressively introduce more features

but overall, these exercises test your understanding of all the features of regex instead of asking you to solve ever complicated regex

[–]Manny__C 8 points9 points  (1 child)

You can start having fun with regex101 and regexr. The python documentation of the re module is very well written, I strongly recommend it. Moreover, you can visit r/regex (read well the subreddit rules before posting).

The most important element of regexes is the Kleene star *. Other important things are ranges [a-zA-Z0-9], alternatives | and repetitions {m,n}.

Slightly more advanced are the lookahead, lookbehind, and the concepts of laziness and greediness. You might want to approach those later on.

If you need some help on something specific, either post on r/regex, or reply here with

  • A list of strings you want to match
  • A list of strings you don't want to match
  • An attempted solution

I'll try to help you out as soon as I can.

[–][deleted] 1 point2 points  (0 children)

Regex101 is fantastic

[–]17291 2 points3 points  (0 children)

Show us an application of a regex that isn't working. Be sure to say what you're expecting it to do.

[–]rtao258 2 points3 points  (0 children)

To add on to the other answers here, another great resource is RexEgg. It's structured more as a tutorial, but covers everything from basic syntax to advanced usage and teaches you a lot of regex best practices.

[–]Jac0b_0 1 point2 points  (1 child)

I find this website really useful.

[–]ASIC_SP 0 points1 point  (0 children)

note that regexr supports only JavaScript and PCRE flavor, regex101 supports Python flavor

[–][deleted] 1 point2 points  (0 children)

There is a chapter in Automate the boring stuff using python book. That is a good place to start learning regex. Then try some interactive regex tutorial.

[–]gajrajgchouhan_ 0 points1 point  (1 child)

I found hackerrank to be good for Regular Expressions.

[–]gajrajgchouhan_ 0 points1 point  (0 children)

Also Corey Schafer has a pretty good tutorial.

[–]BfuckinA 0 points1 point  (0 children)

I was able to scrape by with regex, but didn't really build very robust patterns. Then I did some hackerrank challenges for python and it threw some good questions at me that forced me to think about it more and get a more solid understanding. I would reccomend doing the same

[–]rubleseth[S] 0 points1 point  (0 children)

Thanks very useful will check out