gpt4 book ai didi

python - 如何匹配除空格和换行符以外的任何内容?

转载 作者:太空狗 更新时间:2023-10-29 17:44:48 24 4
gpt4 key购买 nike

我有一个字符串,我只想匹配除空格和换行符之外的任何字符的字符串。什么必须是这个的正则表达式?

我知道除空格以外的任何正则表达式,即 [^ ]+ 和除换行 [^\n]+ 之外的任何正则表达式(我在 Windows 上).我不知道如何将它们组合在一起。

最佳答案

您可以将空格字符添加到要排除的字符类中。

^[^\n ]*$

正则表达式

^              # the beginning of the string
[^\n ]* # any character except: '\n' (newline), ' ' (0 or more times)
$ # before an optional \n, and the end of the string

关于python - 如何匹配除空格和换行符以外的任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23235200/

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