What language/flavor is this? Or I should also ask, if non is specified, what tends to be the default? I'm specifically looking for php or javascript, and I know they're all mostly the same, but not 100%.
David, Regex is programming language neutral, as in, it doesn't matter if you are programming regex expressions in javascript, c#, c++, PHP, or even command line *nix, makes no difference. Only thing you have to watch out for is some programming languages may require different various regex characters to be escaped differently (so the programming language doesn't try to interpret it). Usually a backslash. For instance \\ means ONE backslash in many languages.
Hi, I'm trying to learn REGEX, and I need to find this: "Page 1 Of 60", ..... "Page 50 of 60", But I can't find it using reg. expressions! :(. How would you do that? Thank you!
@david, this cheat sheet is pretty neutral. The most common flavor is Perl Compatible Regular Expressions (PCRE). Javascript's engine is close to that and PHP also has Perl Compatible functions for Regex; they use the PREG prefix. Most everything on this sheet should be supported by PHP's engine (I think POSIX character classes are not). Javascript's engine isn't as featureful. Some advanced features aren't supported, but all the basics are there. If you need a multiline match and you can't use the flag, you can use an inverted class range such as [\s\S] in place of the . (dot) to match anything including newlines.
@Chilean+kris w, You need to find a resource for learning Regular Expressions. This cheat sheet is for reference, not learning. Check out http://www.regular-expressions.info/
I was confused by the first comment (which was wrong, but you compounded the error with an acknowlegement). ^ is the start of string or line. Period.
Also, your cheat sheet is better organized than the more comprehensive http://www.regular-expressions.info/
since its more succinct. The latter has a 1-page summary but its too verbose.
Hey Dave. Thanks for the cheat sheet. You may want to change "Not a or b or c" when you describe the [^abc} negated character class, because in English, the negation is ambiguous. It could mean "neither a nor be nor c." Or the "a" could be the only negated disjunct. You could mean (~a v (b v c)).
Case Conversion
\l Make next character lowercase
\u Make next character uppercase
\L Make entire string (up to \E) lowercase
\U Make entire string (up to \E) uppercase
\u\L Capitalize first char, lowercase rest (sentence)
Favourited by 90 Members:
Comments
Your regex cheatsheet says ^ is "Start of string" and $ is "End of string"
Hi Doug. I've clarified that section. Thanks for the heads up :)
It looks unchanged to me. ^ still says it's "start of string" and $ still says "end of string". They should be reversed, right?
Actually, I'm sorry, you're right! I was pretty confused there, sorry if I've confused anyone else.
No worries Keith - easy mistake to make!
Can you tag this as 'regex'? Searching for regex on cheatography yields two other results, but not this one.
Would you add \Q... \E to the cheatsheet?
It would be nice to see the list of white space characters
Great resource! Thanks for putting this together and sharing.
What language/flavor is this? Or I should also ask, if non is specified, what tends to be the default? I'm specifically looking for php or javascript, and I know they're all mostly the same, but not 100%.
Thanks!
David, Regex is programming language neutral, as in, it doesn't matter if you are programming regex expressions in javascript, c#, c++, PHP, or even command line *nix, makes no difference. Only thing you have to watch out for is some programming languages may require different various regex characters to be escaped differently (so the programming language doesn't try to interpret it). Usually a backslash. For instance \\ means ONE backslash in many languages.
Very handy, thank you!
Don't forget Perl ;-)
Great and useful stuff!
Hi, I'm trying to learn REGEX, and I need to find this: "Page 1 Of 60", ..... "Page 50 of 60", But I can't find it using reg. expressions! :(. How would you do that? Thank you!
Is there a cheat sheet to the cheat sheet? Is this in plain english anywhere?..."negative lookahead"..huh?
@david, this cheat sheet is pretty neutral. The most common flavor is Perl Compatible Regular Expressions (PCRE). Javascript's engine is close to that and PHP also has Perl Compatible functions for Regex; they use the PREG prefix. Most everything on this sheet should be supported by PHP's engine (I think POSIX character classes are not). Javascript's engine isn't as featureful. Some advanced features aren't supported, but all the basics are there. If you need a multiline match and you can't use the flag, you can use an inverted class range such as [\s\S] in place of the . (dot) to match anything including newlines.
@Chilean+kris w, You need to find a resource for learning Regular Expressions. This cheat sheet is for reference, not learning. Check out http://www.regular-expressions.info/
I was confused by the first comment (which was wrong, but you compounded the error with an acknowlegement). ^ is the start of string or line. Period.
Also, your cheat sheet is better organized than the more comprehensive http://www.regular-expressions.info/
since its more succinct. The latter has a 1-page summary but its too verbose.
Nice sheet.
Is there a reason why the ']' character is not listed under metacharacters? Doesn't that character require to be escaped if searched for?
Hey Dave. Thanks for the cheat sheet. You may want to change "Not a or b or c" when you describe the [^abc} negated character class, because in English, the negation is ambiguous. It could mean "neither a nor be nor c." Or the "a" could be the only negated disjunct. You could mean (~a v (b v c)).
Could be added to the list.
Case Conversion
\l Make next character lowercase
\u Make next character uppercase
\L Make entire string (up to \E) lowercase
\U Make entire string (up to \E) uppercase
\u\L Capitalize first char, lowercase rest (sentence)
I have a database using regex. I am trying to use ^file to get all files with name file_,file ,file_name_date. but it is not working any help
Add a Comment
You are posting a reply. Cancel Reply.
Contents
A quick reference guide for regular expressions (regex), including symbols, ranges, grouping, assertions and some sample patterns to get you started.
Cheatographer
www.addedbytes.com
More by DaveChild
Cheat Sheet Stats
Tags
Related (shares tags with):
Thumbnail