r/linux • u/rmcc4444 • Apr 24 '11
Regular Expressions Cheat Sheet (V2)
http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/2
u/andey Apr 25 '11
huge find my friend, i'm comfortable writing regular expressions, but this will help when writing those tricky expressions
1
u/jdpage Apr 24 '11
For anyone wondering, this is appropriate for Perl, PCRE, Ruby, and Tcl ARE. It is not generally appropriate for BRE, ERE, and GNU, because they are relatively fail and don't support some stuff, or ed/ex/vi/vim/sed/grep RE, where different characters have to be escaped, and don't support the same character classes (or shorthands).
4
Apr 24 '11
And just in case anyone is irritated by GNU grep, check out the -P flag, which makes things much better :)
1
u/jdpage Apr 24 '11
It's great, I use it for anything more complex than a simple wildcard match. It turns it into a nice little frontend to PCRE.
1
u/driver8 Apr 24 '11
The sample patterns are pretty silly (by which I mean bad). And I've never seen angle brackets (< and >) used as a metacharacter in regular expressions. What implementation does this?
2
u/DaveChild Apr 25 '11
The samples were so people could see how the various parts can fit together, rather than patterns people could take and use. They do need to be fixed (or replaced) so please do feel free to suggest improvements.
The tricky bit is getting a useful pattern into only a few characters that people may be able to relate to when they are just getting started with regex patterns. I figured PHP devs would be most likely to find this cheat sheet, hence the web-focus to the samples.
1
6
u/broken_cogwheel Apr 24 '11
If you use that example email pattern for validation: I hate you.