Quantifier | Same as | Meaning |
* | {0,} | Match 0 or more times |
+ | {1,} | Match 1 or more times |
? | {0,1} | Match 0 or 1 time |
{n} | Match exactly n times | |
{n,} | Match at least n times | |
{n,m} | Match at least n but not more than m times |
Quantified regular expression always try to match the longest possible sequence of characters (unless the extra '?' is present in which case the shortest possible match is taken). But first, a regex always tries to match at the earleist possible character position in the string.
Because regular expression matching tries to match the maximim,
to find the first ':' in a string like:
spp:Fe+H20=Fe)2;H:2112:100:Haryy Potter:/home/ontherange:/bin/corkthe use of /.+:/ will match up to 'ontherange', so instead use: /[^:]+:/ which will match up to the first ':'. Alternately use the '?' quantifier as in /.+:?/ which will stop at the first ':'.