Greedy and Reluctant Qualifiers
A common gotcha when using regular expressions occurs when using the default (greedy) qualifiers + ? and *. These qualifiers will attempt to make the longest match they possibly can.
The regular expression:
/'(.*)'/will successfully match and group the word there in hello 'there', but will actually run on to the last single quote in the string hello 'there' how are 'you', matching there' how are 'you.
One solution is to restrict the set of characters you are searching for with the greedy qualifier, thus ensuring the match will finish before hitting the terminating character:
/'([^']*)'/This works, but the more readable option is to turn the greedy qualifier into a reluctant one:
/'(.*?)'/By adding a ? to the qualifier the expression will try to match the minimum string that satisfies the expression.