Pages

Tuesday, October 9, 2012

Testing your Regex skills

Regular expressions are powerful, yes. They should not be used for everything, especially not HTML. HTML is not a regular language. As soon as you need some logic, like checking dates, it is out as well. However, it is tredemously helpful for many things. I suggest regular-expressions.info for a very good round-up and a nice collection.

Now that you know that you must not use it everywhere, nothing stops you from trying. For example, when using a text editor, you might want to write a simple Regex to match some HTML just to find where it is in all your code, it does not have to be perfect, just good enough. @callumacrae has made a nice website where he posts a challenge every tuesday. http://callumacrae.github.com/regex-tuesday/

Here are my answers so far. They are not perfect, I have taken quite a few shortcuts, but it should get you started.

  1. Repeated words
  2. Grayscale colours
  3. Dates
  4. Italic MarkDown
  5. Numbers
  6. IPv4 address

No comments:

Post a Comment