gpt4 book ai didi

regex - Perl 正则表达式量化 Error precced

转载 作者:行者123 更新时间:2023-12-03 07:21:07 26 4
gpt4 key购买 nike

当我在 precced 中使用量化时,返回此错误,请参阅多个示例:

printf 'Joe Satriani\nWhitney Houston\n' | grep -Poi '(?<=J\w)[\w\s]+'
e Satriani

printf 'Joe Satriani\nWhitney Houston\n' | grep -Poi '(?<=J\w+)[\w\s]+'
grep: lookbehind assertion is not fixed length

printf 'Joe Satriani\nWhitney Houston\n' | grep -Poi '(?<=J\w{2})[\w\s]+'
Satriani

我不能在 precced 中使用量化吗?

最佳答案

在Perl中,所有可以通过lookbehind匹配的字符串必须具有相同的长度。显然,这与您的 grep 工具相同。

在 Perl 中,您的问题可以使用捕获来解决。

say $1 if /J\w+\s+(\w[\w\s]*)/;

在 Perl 中,\K 在进行替换时通常可用于解决类似问题,并且看起来 grep 也支持它!

$ printf 'Joe Satriani\nWhitney Houston\n' | grep -Poi 'J\w+\s+\K\w[\w\s]*'
Satriani

我很感动!

关于regex - Perl 正则表达式量化 Error precced,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10958447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com