Every time I had to go to the lovely Rubular (http://rubular.com/) just to take a look at their Regex Quick Reference, I thought of composing a list of my own, a bit more detailed though. There are a dozen Regex hacks that I keep forgetting that are really useful and I have to look them up every time. Well, hopefully with this list that won't have to happen again. And if you think of something that is missing, please leave a comment and I will add it. Revision 4 (Each revision extends the article with new hacks. I'll bump the number whenever I add something new) Skip and go to Hacks (#hacks) TL;DR { Basic Regex Reference Groups & Modifiers (Options) } Hacks Match everything until a sequence Looking at the groups reference above, you can do that with a lookahead expression, like so: /.+?(?=foo)/ This will match everything until the string foo. To capture everything until foo, you can use the following: /(.+?)(?=foo)/ Make sure you include the ? in the first capture group or otherwise that will result in an empty capture group at the end. Capture everything until an optional sequence Because Regex engines are greedy, what I showed above wont work with just adding an optional modifier to it (?). Instead you should do this: (.+?)(?:foo|$) This will capture both abc and abcfoo. Greediness vs. Laziness By default Regex is greedy. It would try to match as much as possible when you use operators like + or *. But sometimes you might only need to match more than one but as few as possible. This could be done by switching from Greedy mode to Lazy mode and is achieved by just adding a ? to the multiple operator like: +? or *?. This feature of Regex is called Possessive Quantifiers. Here is a detailed example matching the string abbbbbc: The regex: a(b+) would match abbbbb with the first capture group being bbbbb. The regex: a(b+?) would match ab with the first capture group being b. Now a bit more interesting The regex: a(b+)(b+)c would match abbbbbc with the first capture group being bbbb and the second being b. The regex: a(b+?)(b+)c would match abbbbbc with the first capture group being b and the second being bbbb See how that reversed the order of the matches. Because greediness and laziness change the order in which permutations are tried, they can change the overall match. However, they do not change the fact that the regex engine will backtrack to try all possible permutations of the regular expression in case no match can be found. Possessive quantifiers are a way to prevent the regex engine from trying all permutations. This is useful for performance reasons. You can also use possessive quantifiers to eliminate certain matches. P.S. This article could have been called: Harry Potter and the Power of Regex