RegEx常规模式匹配不适用于相应的文本文件

时间:2016-03-16 03:56:22

标签: java regex

对于特定的单词,我必须获取完整的句子/句子(直到完全停止)。在那个不包括小数点(3.75)。

示例

特定字词:" Abatacept"

段落

  Review of Systems:
General:  Complains of chills, sweats, and malaise; denies fever, anorexia, fatigue, weakness, weight loss, and sleep                                          
disorder.
CV: Denies difficulty breathing at night, near fainting, chest pain or discomfort, racing/skipping heart beats, fatigue, 
lightheadedness, shortness of breath with exertion, palpitations, swelling of hands or feet, difficulty breathing while lying 
down, fainting, leg cramps with exertion, bluish discoloration of lips or nails, and weight gain 3.785 **Abatacept**.
Resp: Complains of cough; denies sleep disturbances due to breathing, shortness of breath, coughing up blood, chest 
discomfort, wheezing, excessive sputum, and excessive snoring.

从Paragraph,我想要与Abatacept一词匹配的句子/句子。 这句话是:

CV: Denies difficulty breathing at night, near fainting, chest pain or discomfort, racing/skipping heart beats, fatigue, 
    lightheadedness, shortness of breath with exertion, palpitations, swelling of hands or feet, difficulty breathing while lying 
    down, fainting, leg cramps with exertion, bluish discoloration of lips or nails, and weight gain 3.785 **Abatacept**.

代码:

word_re = "((\\.(\\s|\\r).*)|(((?!\\.\\s).)*))(\\b(Abatacept)\\b.*?)((\\.\\s)|(\\.\\D)|(\\.$))";
Pattern re = Pattern.compile(word_re ,Pattern.MULTILINE | Pattern.COMMENTS |  Pattern.CASE_INSENSITIVE);
                Matcher match = re.matcher(textString);
                String sentenceString="";
                while (match .find()) {
                    sentenceString = match.group(1);
                    System.out.println(sentenceString);
                }
你能建议我吗?所以我可以从textFile中获取完美的句子/句子,其中有特定的单词。 谢谢。

1 个答案:

答案 0 :(得分:0)

我不确定java,但你可以使用这个正则表达式:

(.*\bAbatacept\b.*[\b(.\s)])

Demo