Bash和TCL的正则表达式
Regular Expression of Bash and TCL
BASH和TCL的正则表达式(REs)一样吗?
我可以将相同的 BASH RE 放入 TCL 的 regexp
函数中吗?它会给我相同的结果吗?
谢谢
Bash 正则表达式 documented 为:
When [the ‘=~’ operator] is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex3)).
Tcl
正则表达式 documented 为:
DIFFERENT FLAVORS OF REs
Regular expressions (“RE”s), as defined by POSIX, come in two flavors: extended REs (“ERE”s) and basic REs (“BRE”s). EREs are roughly those of the traditional egrep, while BREs are roughly those of the traditional ed. This implementation adds a third flavor, advanced REs (“ARE”s), basically EREs with some significant extensions.
This manual page primarily describes AREs. BREs mostly exist for backward compatibility in some old programs; they will be discussed at the end. POSIX EREs are almost an exact subset of AREs. Features of AREs that are not present in EREs will be indicated.
因此,您可以将 bash 正则表达式与 Tcl 正则表达式引擎一起使用,但反之则不一定。
请注意,bash 正则表达式可能有额外的引号,需要针对 Tcl 进行更改。
BASH和TCL的正则表达式(REs)一样吗?
我可以将相同的 BASH RE 放入 TCL 的 regexp
函数中吗?它会给我相同的结果吗?
谢谢
Bash 正则表达式 documented 为:
When [the ‘=~’ operator] is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex3)).
Tcl 正则表达式 documented 为:
DIFFERENT FLAVORS OF REs
Regular expressions (“RE”s), as defined by POSIX, come in two flavors: extended REs (“ERE”s) and basic REs (“BRE”s). EREs are roughly those of the traditional egrep, while BREs are roughly those of the traditional ed. This implementation adds a third flavor, advanced REs (“ARE”s), basically EREs with some significant extensions.
This manual page primarily describes AREs. BREs mostly exist for backward compatibility in some old programs; they will be discussed at the end. POSIX EREs are almost an exact subset of AREs. Features of AREs that are not present in EREs will be indicated.
因此,您可以将 bash 正则表达式与 Tcl 正则表达式引擎一起使用,但反之则不一定。
请注意,bash 正则表达式可能有额外的引号,需要针对 Tcl 进行更改。