This is more of a question related to regular expressions than to
Java. It may be better to brush up on regex, to get up to speed on these types of questions.
And BTW, for those who are wondering... The code examples posted by Aum is Perl -- not Java.
Henry