gpt4 book ai didi

python - 正则表达式条件 : letters except 'crfl' at the end of the word or string are deleted?

转载 作者:太空狗 更新时间:2023-10-30 01:28:02 26 4
gpt4 key购买 nike

我试过:

re.sub(r'[^crfl](?=(\.|\,|\s|\Z))', '', val, flags=re.I)

在字符串上

car. cupid, fof bob lol. koc coc, cob 

但结果是:

car cupi fof bo lol koc coc co

我不明白,为什么先行断言删除了逗号和点。

我要的结果是:

car. cupi, fof bo lol. koc coc, co

最佳答案

[^crfl.,](?=(\.|\,|\s|\Z))

只需将 ., 包含在 negation list 中。参见演示。

https://regex101.com/r/yX8zV8/5

或简单地

\w(?<![crlf])\b

查看演示。

https://regex101.com/r/eB8xU8/1

关于python - 正则表达式条件 : letters except 'crfl' at the end of the word or string are deleted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35173116/

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