![]() The idea with awk as I see it is that you're supposed to use regular expression for straight time- and memory-bounded matches, and its C-like turing-complete language for anything more complex than that. Such an implementation cannot support backreferences in any form (it can support capture groups, though the implementation is not straight-forward). This may be going beyond the question, but the reason why awk doesn't support backreferences is because awk has always used real regular expressions, ie ones that can be implemented without recursion by a finite-state machine. ![]() GNU and busybox sed do support back-references with -E but FreeBSD's sed doesn't. Some sed implementations support extended regexps with -r or -E, and POSIX will specify -E in the next major version of the standard, but still not back references (though capture groups for s's replacement will). Sed regular expressions are basic regular expressions that do support back references. With standard utilities, you'd typically use sed for that job: sed 's/\(_]\)\1/&\1/g' Like with sub() and gsub(), you have to use "." instead of /./ and use \\1 instead of \1 (in standard awk, "\1" is the character of value 1 ( ^A), and /\1/ is required to match that character while "\\1" is (well was) un(der)specified in POSIX also note that POSIX EREs don't have back-references, that's the one feature BREs have but not EREs). It does happen to also support gawk's gensub() and \w extensions: ![]() The busybox implementation of awk is the only one that I know that supports back-references.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |