Previous: , Up: Regexp Operators   [Contents][Index]

3.3.2 Some Notes On Interval Expressions

Interval expressions were not traditionally available in awk. They were added as part of the POSIX standard to make awk and egrep consistent with each other.

Initially, because old programs may use ‘{’ and ‘}’ in regexp constants, gawk did not match interval expressions in regexps.

However, beginning with version 4.0, gawk does match interval expressions by default. This is because compatibility with POSIX has become more important to most gawk users than compatibility with old programs.

For programs that use ‘{’ and ‘}’ in regexp constants, it is good practice to always escape them with a backslash. Then the regexp constants are valid and work the way you want them to, using any version of awk.16

Finally, when ‘{’ and ‘}’ appear in regexp constants in a way that cannot be interpreted as an interval expression (such as /q{a}/), then they stand for themselves.

As mentioned, interval expressions were not traditionally available in awk. In March of 2019, Brian Kernighan’s awk (finally) acquired them.

Nonetheless, because they were not available for so many decades, gawk continues to not supply them when in compatibility mode (see section Command-Line Options).



Use two backslashes if you’re using a string constant with a regexp operator or function.