views:

273

answers:

6
+5  Q: 

Practicing regex

I'd like to learn regex better so that it becomes a more natural option for me. Often problems that could be solved easily by regex I don't even consider using it.

Can someone direct me to a resource that gives challenging regex problems like the one in the python challenge that goes something like this but in more of a riddle like fashion:

given a text file with lower and uppercase letters, match all lowercase letters surrounded by exactly 3 uppercase letters.

that's just the jist of one of the problems there... it's ok if the problems are not as obvious as the example.

edit: just to clarify... i'm not looking for software, i'm looking for problems. But I'll make this a wiki so's we can get as many resources here as possible.


Here's what's been given so far both in terms of problem sets and software as well as other stuff I've found.

Problems

Regex SW

Damn... a ton of stuff on regexlib

Related Posts on SO

+2  A: 

Can I suggest something different to practice regex from my personal expreience?

How about applying it while, working for example, you just merged some code and you got some conflicts which you accidently marked as resolved? How can I find all the files the where conflicting? Write a regular expression to search your code for conflict marks (<<<< ==== etc ...)

Another example, some one refactored a Class that you where using all over your code, it was called foo.bar.baz; now it is bar.baz.foo; write a regular expression to find and replace all of the first with the second.

These examples, may or may not be relevant to your work but I am sure you will encounter the need to use regular expressions in your day to do day activities. When you encounter it, be brave go use regular expressions :) It will slow you down a little a the start but once you get more comfortable, you would have achieved your aim.

hhafez
And back up that code first!
Ed Swangren
you don't need to do that, it will work 100% right from the first time lol
hhafez
+1  A: 

You can probably find some gems in the programming contests site: here. Granted, these are not specific to regular expressions, but there are bound to be a few there whose solutions fall in this domain.

javamonkey79
+9  A: 

Search for regex tagged questions on Stack Overflow and try answering them.

Curtis Tasker
+1: Answer every regex question for a week and you'll know what to do and what NOT to do.
S.Lott
There are currently 2400 regex questions. That will keep you busy for a while.
S.Lott
Or at least learn why the given answers work or not.
Simeon Pilgrim
A: 

You could try out RegexCoach. It lets you interactively experiment with regular expressions against your own target string.

A: 

Work at the command line (or a shell-oriented window editor like Acme or Wily) and use sed and awk to transform the data you work with from its raw form to the formats in which you would like to see it, or the formats in which other programs need it. Since sed and awk use regular expressions to find lines to work on (by pattern-matching), you'll develop your skills at the same time as you learn these tools.

I suggest working at the command line because every bit of data and scripts there are text that to do anything with you must find and process, often from a much larger file. So you can use grep's regular expressions too to reduce the number of lines to consider, but I usually just use

sed -n -e '/regexp/p'

to find lines since I can update it later with a substitution

sed -e '/lineregexp/s,oldregex,newtext,'

For a really advanced use, you can use sed to update scripts at runtime instead of coding in complicated if/case statements or command-line options, or even change the script's structure, but that's beyond the scope of this answer.

Edit: removed p from second example.

Jason Catena
+1  A: 

I highly recommend Expresso (http://www.ultrapico.com/Expresso.htm), especially if you're using .NET. It's good for both building and analyzing regular expressions, and will generate code, as well. It's saved me many, many hours.

Steven Sudit