php preg_match_all,在可用时返回多个可选值
大海捞针的例子:
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
正如你所看到的,有时有时间( - H:MM AM/PM),有时是“药物管理路线:...”和“剂量:...”,我总是想要名称(Versed) 、氧气等)以及如果可用 - 时间(H:MM AM/PM)、途径(静脉注射、口服等)和剂量(20.00 MG、2.00 L/MIN 等)全部存储在数组中。我以为我过去曾经拥有过它,但是当我向它扔一个不同的干草堆时,它失败了......还要注意,有时似乎在变量之间有一个选项卡而不是空格,例如 time-Admin 或管理剂量...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
幸运的是,我在午休期间有一些空闲时间:)
在正则表达式中,表达式后面的
?
表示它将接受一次或零次出现。每个示例:在您的情况下,通过正则表达式有点难以做到,但无论如何都是可行的:
然后对数组进行后处理:
这应该给您:
这里唯一的问题是“Med Admin Route”位。它必须是单个单词(即:没有空格)。
Luckily for you, I have some time on my hands during my lunch break :)
In regex,
?
after an expression means that it will accept one or zero occurences. Per example:In your case, it is a little hard to do by regex, but feasible anyway:
Then post-process the array:
This should give you:
The only issue here is the "Med Admin Route" bit. It must be a single word (i.e.: no spaces).
感谢 phpfreaks.com 的工作人员,完成了工作
Got the job done thanks to the guys at phpfreaks.com