python - Python Regex:Findall从字符串的开头到结尾匹配字符串
问题描述
text = "A random\string here"
test = re.findall('(?<=A ).+\s', text)
我只想打印从“A”结尾(不包括空格)到字符串结尾的所有内容。
我只想得到“随机\字符串”
解决方案
如果您想要简单的东西,我建议使用 split 而不是正则表达式(类似于 <code>test=text.split('A')[1])
如果你真的想使用正则表达式,你可以使用这种网站来调试它:https ://regex101.com/
推荐阅读
- php - 如何使用 php 将 Json 打印到 Utf8
- angular - TypeScript Angular ReactiveForms 2 方式属性绑定
- javascript - 从 MediaRecorder blob 部分创建新的 Blob 会导致空 Blob
- python - 带有熊猫样式格式的表格和链接格式
- c# - 识别 XDocument 中的 HTML 节点以替换并转换为 Json
- java - 在 Java 中评估 XPath 表达式时出现异常
- java - 尝试计算相同的值两次时,HashMap 的循环不正确且超出范围
- c++ - Direct X 9 -“对 Direct3DCreate9@4 的未定义引用”
- android - 即使在交换属性后,Android 资源编译也会失败
- javascript - 将 HTML/JavaScript 形式的答案保存到用户指定的 .txt 文件时遇到问题