Seeking interesting regex samples
by Turbocapitalist from LinuxQuestions.org on (#50TJD)
I am looking to collect a samples of interesting or particularly useful regular expressions. POSIX, Extendend, or PCRE are all good. I've seen RexEgg, Ryan's Tutorial's Regular Expressions!, and the Regular Expressions Tutorial to name three. I've also cruised through a bit of code but the syntax is not something that can easily be found genericly with grep. So I am asking for what you recall:
Which interesting and/or useful patterns have you seen, made, and/or used?
Myself, I have recently dealt with this one to place commas in a rather long number:
Code:s/(\d)(?=(\d{3})+$)/$1,/g;Strip leading and trailing white space:
Code:s/^\s+//; s/\s+$//;Strip hidden Unicode word joiner:
Code:s/\x{2060}//g;However, it has not occured to me to keep note of them over the years and most have been one-offs. It would be interesting to know which regular expressions have been particularly useful or interesting, especially the longer, more complex ones.


Which interesting and/or useful patterns have you seen, made, and/or used?
Myself, I have recently dealt with this one to place commas in a rather long number:
Code:s/(\d)(?=(\d{3})+$)/$1,/g;Strip leading and trailing white space:
Code:s/^\s+//; s/\s+$//;Strip hidden Unicode word joiner:
Code:s/\x{2060}//g;However, it has not occured to me to keep note of them over the years and most have been one-offs. It would be interesting to know which regular expressions have been particularly useful or interesting, especially the longer, more complex ones.