在两个单词之间提取字符串

时间:2014-07-24 10:57:24

标签: ruby regex

  • 从这个字符串:

    "Patient Gia Gottlieb's encounter with Dr. Madge Bahringer"
    

    我需要在单词Gia Gottlieb之后的单词PatientDr.以及医生姓名Madge Bahringer之间提取患者姓名Dr.

  • 从这个字符串:

    "Service Check 14 - cost $2271.00"
    

    我需要提取服务名称Check 14并花费2271.00

请帮助。

1 个答案:

答案 0 :(得分:1)

如果你有一个固定的模板,你可以简单地用catch-alls替换空格:

s.scan /Patient (.+)\'s encounter with (.+)/
# => [["Gia Gottlieb", "Dr. Madge Bahringer"]]

以同样的方式:

s2.scan /Service (.+) - cost \$(.+)/
# => [["Check 14", "2271.00"]]