Two numbers in brackets

If there are two numbers, n and m, in brackets, then it means that the preceded item must be matched at least n times but not more than m times. The values of n and m must be non-negative and smaller than 255. For example, to match the occurrence of a minimum of 2 numbers and a maximum of 6 numbers between a and b in a line, we can use the following regular expression:

$ awk '/a[0-9]{2,6}b/'  interval_regex.txt

The output on execution of the preceding code is as follows:

a12b
a123b
a1234b
a12345b
a111b
a111111b

In interval expression, the preceding regular expression should be a single-character regular expression, or if it is a string, it must be enclosed in a bracketed regular expression. For example:

$ awk '/(ab){2,3}/'  interval_regex.txt

The output on execution of the preceding code is as follows:

cababababt
cababt

A summary of interval expressions is as follows:

Pattern

Matches

A{3}B

Matches the line with AAAB

A{3,}B

Matches AAABAAAAB,or AAAAAB, and so on

A{3,5}B

Matches AAABAAAAB, or AAAAAB

{4,8}

Matches any line with {4,8}

X(ab){2}Z

Matches any XababZ

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.17.40