psam
psam

Reputation: 13

antlr How to specify regular expressions with the repitition between 2 to infinity

How to specify regular expressions with the repitition of ANTLR between 2 to infinity

Thanks

Upvotes: 1

Views: 51

Answers (1)

Ira Baxter
Ira Baxter

Reputation: 95324

You can specify with most regexes the notion of 0 to infinity as:

   (re)*

1 to infinity is usually expressed as:

   (re)+

but in fact you can write this as equivalently as

   (re)((re)*)

Using the same idea, 2 to infinity can be written as:

   (re)((re)+)

Any "N to infinity" can be expressed as:

   (re_1)(re_2)...(re_N) ((re)*)

where there are N (re) followed by re star.

Upvotes: 1

Related Questions