如何使用正则表达式

时间:2017-02-23 18:17:34

标签: regex

我有以下数据:

示例1

Barium swallow : There is slow transit to the stomach.
There is lots of other stuff going on.
There is no aspiration.
Conclusion: Appearances are consistent with achalasia.

示例2

Barium swallow : There is slow transit to the stomach.
There is no evidence of achalasia here.
There is no aspiration.
Conclusion: Normal study

示例3

Barium swallow : There is slow transit to the stomach.
There is no reflux.
There is no aspiration.
Conclusion: Possible achalasia

我想摆脱'no' and achalasia之间的话,但仅限于一行,以便通过上面的例子我得到

示例1

Barium swallow : There is slow transit to the stomach.
There is lots of other stuff going on.
There is no aspiration.
Conclusion: Appearances are consistent with achalasia.

示例2

Barium swallow : There is slow transit to the stomach.
There is.
There is no aspiration.
Conclusion: Normal study

示例3

Barium swallow : There is slow transit to the stomach.
There is no reflux.
There is no aspiration.
Conclusion: Possible achalasia

要做到这一点(在R中)我使用以下正则表达式:

[Nn]o.*[Aa]chalasia.*?(\\.\\n|\\.$)

然而,我得到了:

示例1

Barium swallow : There is slow transit to the stomach.
There is lots of other stuff going on.
There is no

示例2

Barium swallow : There is slow transit to the stomach.
There is no aspiration.
Conclusion: Normal study

示例3

Barium swallow : There is slow transit to the stomach.
There is no reflux.
There is no

1 个答案:

答案 0 :(得分:0)

好的,所以我想出来了。这个问题不是正则表达式,而是当使用带有R的gsub表示正则表达式时,你使用选项perl = T

然后我使用了[Nn]o.*[Aa]chalasia.*?(\\.|$)

做了诀窍