use*_*222 6 awk posix regular-expression
我无法理解或解释为什么以下表达式失败gawk 3.1.x
但在 gawk 中有效4.1.x
:
(最小工作示例)
echo ";#ADCDE#" | awk '/#.{5}#$/'
-> 在 中产生匹配,在gawk 4.1.x
中不产生匹配gawk 3.1.x
echo ";#ADCDE#" | awk '/#.*#$/'
-> 在两者中产生匹配
在如何处理正则表达式方面,gawk 3 和 4 之间有什么变化吗?我不认为重复构造 {n} 对正则表达式来说是新的。如果我使用字符类或 [AZ] 更改点 (.),则会发生相同的行为
X T*_*ian 11
--posix
在 3.1 中添加作品
echo ";#ADCDE#" | gawk --posix '/#.{5}#$/'
Run Code Online (Sandbox Code Playgroud)
我有
awk --version
GNU Awk 3.1.6
...
Run Code Online (Sandbox Code Playgroud)
从我的man awk
页面
r{n}
r{n,}
r{n,m} One or two numbers inside braces denote an interval expres?
sion. If there is one number in the braces, the preceding
regular expression r is repeated n times. If there are two
numbers separated by a comma, r is repeated n to m times.
If there is one number followed by a comma, then r is
repeated at least n times.
Interval expressions are only available if either --posix or
--re-interval is specified on the command line.
Run Code Online (Sandbox Code Playgroud)