douya1855 2011-02-09 18:10
浏览 231
已采纳

php preg_match_all,在可用时返回多个可选值

Example of the haystack:

INTERVENTIONS:
---------------------
Med Given: Versed - 9:50 PM Med Admin Route: Intravenous    Dosage: 20.00 MG
Med Given: Lidocaine - 9:50 PM  Med Admin Route: Intravenous    Dosage: 150.00 MG
Med Given: Succinylcholine - 9:50 PM    Med Admin Route: Intravenous    Dosage: 200.00 MG
Med Given: Oxygen - 7:23 PM Dosage: 2.00 L/MIN
Med Given: Vancomycin
Med Given: Fentanyl
Med Given: Dopamine
Med Given: Dextrose
Med Given: Gentamicin

As you cans see, sometimes there are times ( - H:MM AM/PM), sometimes "Med Admin Route: ..." and "Dosage: ...", I always want the name (Versed, Oxygen, etc) and if available - the time (H:MM AM/PM), route (Intravenous, Oral, etc) and dosage (20.00 MG, 2.00 L/MIN, etc) all stored in an array. I've thought that I've had it in the past but when I throw a different haystack at it it fails... Also note that it appears that sometimes there is a tab instead of a space between the variables like time-Admin or Admin-Dosage...

  • 写回答

2条回答 默认 最新

  • dongzhi4498 2011-03-03 17:19
    关注
    preg_match_all('~Med Given: ((?:(?!-\s*\d{1,2}:\d{1,2} (?:A|P)M|Med Admin Route:|Dosage:|$).)+)(?:\s*-\s*(.*?(?:A|P)M))?(?:\s*Med Admin Route:((?:(?!Dosage:|$).)+))?(?:\s*Dosage:\s*(.*))?~',$content,$matches);
    

    Got the job done thanks to the guys at phpfreaks.com

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持