【问题标题】:Regular Expression to Select Particular Text选择特定文本的正则表达式
【发布时间】:2018-10-03 06:21:55
【问题描述】:
<b>Dummy Alerts: </b>3/3Alerts have been addressed&#10; Question Alert: Have you had problems or are your volumes lower than normal?  " +
            "Yes Alert is closed on 01/09/2018 at 01:08 PM&#10; Question Alert: Have you been drinking more fluid? " +
            " Yes Alert is closed on 10/09/2019 at 01:08 PM&#10;&#10;Ram support visit performed 10/9/17,  Weight 90.2kg (dry). " +
            "TW achieved. No peripheral edema. BP within routine range per patient history. Urine output 1050ml. No PO fluid restriction at this time. " +
            "Patient did forget to bring in flow sheets.  Monitor UF trend with flow sheet review in one week. Michelle Mayhew Smith, RN."

我有很多类似的记录。

我要选择:-

 Ram support visit performed 10/9/17,  Weight 90.2kg (dry).
            TW achieved. No peripheral edema. BP within routine range per patient history. Urine output 1050ml. No PO fluid restriction at this time.
            Patient did forget to bring in flow sheets.Monitor UF trend with flow sheet review in one week. Michelle Mayhew Smith, RN.

在 C# 中使用正则表达式。

你能帮忙吗?

【问题讨论】:

  • 为什么不使用用于解析 HTML 的库,例如 HtmlAgilityPack?
  • 还是按&amp;#10;拆分?
  • 你能解释一下吗..或者举个例子..?
  • 嗯,你显然需要在最后一个&amp;#10;之后的文本。如果是这样,请在下面查看我的答案
  • 关于+ 符号,请注意"bla" + "bla""blabla" 相同。 + 所做的只是将这些字符串连接在一起

标签: c# regex c#-4.0 c#-3.0


【解决方案1】:
using System;

class Program
{
    static void Main()
    {
        string dummyString = "<b>Dummy Alerts: </b>3/3Alerts have been addressed&#10; Question Alert: Have you had problems or are your volumes lower than normal?  " +
            "Yes Alert is closed on 01/09/2018 at 01:08 PM&#10; Question Alert: Have you been drinking more fluid? " +
            " Yes Alert is closed on 10/09/2019 at 01:08 PM&#10;&#10;Ram support visit performed 10/9/17,  Weight 90.2kg (dry). " +
            "TW achieved. No peripheral edema. BP within routine range per patient history. Urine output 1050ml. No PO fluid restriction at this time. " +
            "Patient did forget to bring in flow sheets.  Monitor UF trend with flow sheet review in one week. Michelle Mayhew Smith, RN.";

        // With String.Split    
        var splitted = dummyString.Split(new string[]{"&#10;"}, StringSplitOptions.None);
        Console.WriteLine(splitted[splitted.Length-1]);

        // With String.LastIndexOf & String.Substring
        int lastIndex = dummyString.LastIndexOf("&#10;");
        Console.WriteLine(dummyString.Substring(lastIndex+5));
    }
}

写入两次:

17 年 10 月 9 日进行了 RAM 支持访问,重量 90.2 公斤(干重)。 TW达到了。无外周水肿。 BP 在每个患者病史的常规范围内。尿量1050ml。目前没有 PO 流体限制。患者确实忘记带入流程图。在一周内通过流程图审查监控 UF 趋势。米歇尔·梅休·史密斯,注册护士。

【讨论】:

    猜你喜欢
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多