The first type of operators are the repetitors. Such a repetitor acts only on the single object directly to the left of it. Repetitors are:
repetition element | effect |
take object one or more times | |
* | take object zero or more times |
? | take object zero or one times |
{m,n} | take object at least m, at most n times |
{,n} | take object at most n times |
{m,} | take object at least m times |
{m} | take object exactly m times |
//ab*c/ //a(b*c)*c{4}/ //a[bc]*c{5}/ //"abc"+/The first pattern will match to an a, followed by zero or more characters b, after which there should be a c. The second pattern is more complicated. The first character should be an a. Then we want zero or more times the object
(b*c)
. This object would match any
number of b's followed by a single c. The effect is that (b*c)*
will match any string that contains only the characters b and c, with
the side condition that the last character must be the character c.
Finally there should be 4 more c's. The third pattern shows how this can
be done simpler with the use of a group. The fourth pattern will match
one or more occurrences of the string abc. This means that the +
operates not only on the c. It is equivalent to (abc)+
, but the
searching with the string is much simpler and faster.
Repetitors are always given the maximal value that they can take. This means that the left most repetitor in a pattern tries to match as many characters as possible. Then the next repetitor tries to match a maximal substring. The effect is usually a maximal match.
When no upper limit is mentioned the editor substitutes a maximum of 255. In practice the limits of the pattern matcher may be reached earlier as should be clear from the following pattern:
//(.*\n)+/which should match an entire file, whatever its length (the
\n
indicates a linefeed as explained below). In practise the
editor will display the message
Expression too complicated during matchingafter about 256 characters in the match. After it sees that the match is longer it cannot continue because its internal buffers are full. This restriction may be lifted in the future.