【发布时间】:2022-01-12 16:20:58
【问题描述】:
Sed 没有给我预期的结果。我想获得第 2 组的输出,但 sed 什么也没给我。我在Ubuntu 20.04.3 LTS 上运行了这个命令,我使用的是sed (GNU sed) 4.7。但是当我在 regex101.com 上尝试时,它给了我预期的结果。你可以看到它here。
root@6ab6c9bc0d76:~# cat /etc/issue
Ubuntu 20.04.3 LTS \n \l
root@6ab6c9bc0d76:~# sed --version
sed (GNU sed) 4.7
Packaged by Debian
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
Paolo Bonzini, Jim Meyering, and Assaf Gordon.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
第 2 组为空。
root@6ab6c9bc0d76:~# echo "https://one-two-three-four-five.dev.domain.com" | sed -E "s/(https?:\/\/)([\w|-]*)(.*)/Group1: \1\nGroup2: \2\nGroup3: \3/"
Group1: https://
Group2:
Group3: one-two-three-four-five.dev.domain.com
root@6ab6c9bc0d76:~#
【问题讨论】:
标签: regex bash ubuntu sed command-line-interface