Learning AWK Programming
上QQ阅读APP看书,第一时间看更新

Repetition ranges with interval expressions

We can use interval expressions to specify a minimum, maximum, or exact number of occurrences to match the preceding regular expression. The unary operator for repetition can specify a minimum number of occurrences, but we cannot specify the maximum number of occurrences of the preceding expression with them.

Interval expressions were not originally available in AWK. They were added as part of the POSIX standard to make AWK and egrep consistent with each other. In GAWK, they are available with version 4.0 and above.

Let's create a file to illustrate the interval expression:

vi interval_regex.txt
a1b
a12b
a123b
a1234b
a12345b
a1233456b
a111b
a111111b
cababababt
cababt