什么是正确的正则表达式,可以从以下字符串中提取字符串“(procedure)”或括号内的一般文本?
输入字符串示例如下:
Positron emission tomography using flutemetamol (18F) with computed tomography of brain (procedure)
另一个例子:
Urinary tract infection prophylaxis (procedure)
可能的方法有:
- 到达文本末尾,查找第一个开括号,并将该位置到文本末尾作为子集。 - 从文本开头,识别最后一个“(”字符,并将该位置到结尾作为子字符串。
其他字符串可以是(不同的“标记”被提取)。
输入字符串示例如下:
Positron emission tomography using flutemetamol (18F) with computed tomography of brain (procedure)
另一个例子:
Urinary tract infection prophylaxis (procedure)
可能的方法有:
- 到达文本末尾,查找第一个开括号,并将该位置到文本末尾作为子集。 - 从文本开头,识别最后一个“(”字符,并将该位置到结尾作为子字符串。
其他字符串可以是(不同的“标记”被提取)。
[1] "Xanthoma of eyelid (disorder)" "Ventricular tachyarrhythmia (disorder)"
[3] "Abnormal urine odor (finding)" "Coloboma of iris (disorder)"
[5] "Macroencephaly (disorder)" "Right main coronary artery thrombosis (disorder)"
寻求通用正则表达式(或者更好的解决方案是在R中)
FELON IN POSSESSION OF AMMUNITION (ACTUAL POSSESSION) (79023)
得到 79023。 这个不行:FAIL TO DISPLAY REGISTRATION - POSSESSION REQUIRED (320.0605(1))
。它应该给出 320.0605(1)。有什么办法修改这个答案以允许嵌套括号吗? - OscarVanL