鱼C论坛

 找回密码
 立即注册
查看: 2113|回复: 1

[已解决]正则匹配问题

[复制链接]
发表于 2020-11-30 22:44:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
基因测序法Bacillus hisashii(NR144578.1)99.789%     
基因测序法Bacillus hisashii;NR144578.2;99.7%  
基因测序法Bacillus hisashii NR144578.1 100%  
基因测序法Bacillus sp.(NR144578.1)99.739%
基因测序法Bacillus hisashii;NR144578.1;99.743%

匹配以上字符串中的英文名称和最终的百分比,我用的正则是
r'基因测序法([a-zA-Z]+ [a-zA-Z.]+).*(\d+\.?\d+)%'
总是出错,求大神指点,不胜感激!
最佳答案
2020-12-1 09:57:14
  1. import re

  2. st1 = '''
  3. 基因测序法Bacillus hisashii(NR144578.1)99.789%     
  4. 基因测序法Bacillus hisashii;NR144578.2;99.7%  
  5. 基因测序法Bacillus hisashii NR144578.1 100%  
  6. 基因测序法Bacillus sp.(NR144578.1)99.739%
  7. 基因测序法Bacillus hisashii;NR144578.1;99.743%
  8. '''


  9. result = re.findall(r'法(.*?).NR.*?[; ;\)](.*?)%', st1)
  10. print(result)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-12-1 09:57:14 | 显示全部楼层    本楼为最佳答案   
  1. import re

  2. st1 = '''
  3. 基因测序法Bacillus hisashii(NR144578.1)99.789%     
  4. 基因测序法Bacillus hisashii;NR144578.2;99.7%  
  5. 基因测序法Bacillus hisashii NR144578.1 100%  
  6. 基因测序法Bacillus sp.(NR144578.1)99.739%
  7. 基因测序法Bacillus hisashii;NR144578.1;99.743%
  8. '''


  9. result = re.findall(r'法(.*?).NR.*?[; ;\)](.*?)%', st1)
  10. print(result)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-30 12:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表