[Image of Linux]
The Personal Web Pages of Chris X. Edwards

Regular Expression Tutorial

--------------------------

Limiting Quantifier

The predefined quantifiers are sufficient for almost all regular expression work, but in rare cases, even more quantifier control is needed. Most regular expression engines provide a system to explicitly define acceptable quantities. This syntax looks like this:
{min,max}
The "min" is a number that represents the minimum number of the modified character to accept as a match. The "max" specifies the maximum number of these characters allowed.

re-1000limit


Matches "10", "100", and "1000", but neither "1" nor "10000"..

If there is no maximum or minimum limit, you can leave that out allowing for a maximum limit quantifier and a minimum limit quantifier.
{min,}
/10{3,}/
Matches "1000", "10000", "100000000", etc, but not "100".
{,max}
/10{,3}/
Matches "1", "10", "100", and "1000", but only partially matches "10000", "1000000", etc. In this case, the match finds the first 1000 and ignores the rest.

Specific Quantifier

It is also possible to specify exactly how many you want to require for a successful match. The quantifier format looks like this:
{num}

Here's an example:

re-100comma000

This will match "1,000", "10,000", "100,000", but not "1000,000".

--------------------------

If you've made it this far, good job! You must be really interested in regular expressions and you are finding my tutorial helpful. Unfortunately, this is the last lesson that I've prepared. There are lots of other neat things one can do with regular expressions:

And there are intricate controls for very sublte aspects of the pattern match: Hopefully you've got a good enough grasp of the fundamentals that you can now play around with a regular expression capable tool (I recommend Vim or Perl) and learn more on your own. Good luck!

--------------------------
Previous Home Next
This page was created with only free, open-source, publicly licensed software.
This page was designed to be viewed with any browser on any system.
Chris X. Edwards ~ December 2003