Introduction

Syntax

Program Help

Examples

Download

Match Tool 2.1

Match Tool 3.0

 

DEELX Basic Pattern Syntax: Repeat Quantifier

Return: Content | Prev: Custom defined character sets | Next: Character boundary


Repeat Quantifier

Make another expression repeat matching many times.


Remarks

Can make other expression repeat matching fixed times and various times.

By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match.

Quantifier

Description

{n}

Repeat fixed n times, example: "\w{2}" equivalent to "\w\w"

{m, n}

Match n times if possible, m times least, example: "ba{1,3}" can "ba","baa","baaa"

{m, }

As many as possible, m times least, example: "\w\d{2,}" can "a12","x456"...

?

Match 1 time if possible, 0 time if could not match, equivalent to {0, 1}

+

As many as possible, 1 times least, equivalent to {1, }

*

As many as possible, 0 times if could not match, equivalent to {0, }

"Reluctant" quantifier:

If a quantifier is followed by a question mark(?), it becomes a "reluctant" quantifier. Reluctant quantifiers will match the minimum number of times possible.

Quantifier

Description

{m, n}?

Match only m times if possible, at most n times.

{m, }?

Match only m times if possible, can match as many times as necessary.

??

Match 0 time if possible, at most 1 time, equivalent to {0, 1}?

+?

Match only 1 time if possible, can match as many times as necessary, {1, }?

*?

Match 0 time if possible, can match as many times as necessary, {0, }?

"Possessive" quantifiers:

If a quantifier is followed by a plus(+), it becomes a "possessive" quantifiers. Possessive quantifiers, which greedily match as much as they can and do not back off, even when doing so would allow the overall match to succeed.

Quantifier

Description

{m, n}+

Match n times if possible, m times at least.

{m, }+

As many times as possible, m times at least.

?+

Match 1 time if possible, match 0 time if could not, equivalent to {0, 1}+

++

As many as possible, 1 times least, equivalent to {1, }+

*+

As many as possible, 0 times if could not match, equivalent to {0, }+

 

 

RegExLab.com © 2005 - All Rights Reserved