我正在寻找 Python 等价物
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
原文由 siamii 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在寻找 Python 等价物
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
原文由 siamii 发布,翻译遵循 CC BY-SA 4.0 许可协议
import re
s = "many fancy word \nhello \thi"
re.split('\s+', s)
原文由 Óscar López 发布,翻译遵循 CC BY-SA 3.0 许可协议
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
没有参数的
str.split()
方法在空格上拆分: