Monday, August 15, 2005

Regular expressions tutorial

I can never remember Regular Expressions (regex).

So heres a good tutorial on the subject I found. http://www.silverstones.com/thebat/Regex.html

once you've read that, then pick one of the following results as a quick reference card.
http://www.google.ie/search?q=regex+quick+reference


---Added Jul 13 ----
Just found this great site for validating your regex's online.. Brilliant.

http://www.koralsoft.com/regextester/

Regexs
Strip html from strings
//javascript Makes <b>Hello</b> World => Hello World
tag = tag.replace(/(<([^>]+)>)/ig,"");

Split CamelCase word (Note performance might not be great for many iterations)
s.replaceAll("([A-Z])", ' $1'); // taken from here

Slight modification (don't split if more than one capital after another)
s.replaceAll("([A-Z]{1,})", ' $1');

No comments: