python - 如何避免匹配较长的字符串以支持较短的子字符串?
问题描述
我有以下正则表达式,旨在根据社交媒体数据提取参加活动的人数:
我是正则表达式的新手,但我尝试使用 {} 来限制匹配字符的数量。
([0-9]+)?(,)?[0-9]+(\s*(\.|,)\s*[0-9])?\s*(k|K)?\s*(P|p).*e\s*(G|g).*g
问题是它不仅匹配了这个“60 人去”,而且还匹配了这个“184 人感兴趣 20 人去”。
在第一种情况下,它给了我想要的值(即 60),但在第二种情况下,我得到的是 184 而不是 20。
示例 1:
"United Muslims of America shared their event. \nSponsored B \nIf you also think that there should only be peace, come with us on Juney 3 \nand let's make it happen. \nStop warl Stop killing the innocent! \nsrop \nKiLLiNG \nTHE iNNOCENT \nJUN \nLike \nMake peacei not war! \nSat PM EDT The White House Washington, \n184 people interested 20 people going \nComment \nInterested \n"
示例 2:
"BM shared their event. \nSponsored \nWe're proud to announce an initiative focused on providing free legal \neducation to empower our people and strengthen our community. \nWe believe that having these legal workshops on a monthly basis will prove \nto be beneficial in a tangible way for our community \nMeet you at \nLEGAL \nNIGHT A \nCharlotte, NC \nFREE LEGAL INFO FOR COMMUNITY \nJANUARY, 28, 5 PM \nJAN \n28 \nLegal Night at \nSat 5 PM \n95 people interested 18 people going \nCharlotte \n* Interested \n19 Reactions \nLike Comment \n"
解决方案
推荐阅读
- python - 当我打开它以添加新文档时,Whoosh 索引文件被覆盖
- android - 如何将 android 的日期选择器更改为 Material 主题的微调器?
- homebrew - 检测到 Big Sur 潜在提权漏洞的乘客
- angular - Angular Jasmine“无法读取未定义的属性”
- python - 将 Timekeeper Windows Hosts PowerShell 脚本翻译成 Python3 for Linux Hosts
- jenkins-plugins - Selenium Allure 报告数据显示在 Grafana 仪表板上
- python - 写入 csv,导致一些数据保存在单独的行中
- postgresql - 在postgresql中插入触发器,动态语句
- python - 仅从 Libpostal (Pypostal) 获取街道和乡村 - PySpark
- batch-file - 批处理文件 - 无法读取变量