我需要在空格上拆分一个字符串,但我需要忽略一些包含空格的复合关键字.例如,我有一个String如下,
String testCase = "The patient is currently being treated for Diabetes with Thiazide diuretics";
Run Code Online (Sandbox Code Playgroud)
我需要拆分字符串,但需要Thiazide diuretics作为一个整体复合表达式
String[] array = testCase.split(" ");
Run Code Online (Sandbox Code Playgroud)
结果必须如下:
Run Code Online (Sandbox Code Playgroud)The patient is currently being treated for Diabetes with Thiazide diuretics
怎么做 ?
我有一个私有方法,可用于使用RegEx查找药物名称。代码如下
private boolean containsExactDrugName(String testString, String drugName) {
int begin = -1;
int end = -1;
Matcher m = Pattern.compile("\\b(?:" + drugName + ")\\b|\\S+", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(testString);
ArrayList<String> results = new ArrayList<>();
while (m.find()) {
results.add(m.group());
}
boolean found = results.contains(drugName);
return found;
}
Run Code Online (Sandbox Code Playgroud)
它应该带有药物名称,并在文本String中找到完全匹配的内容。这意味着,如果药物名称为,insuline并且字符串文本为The patient is taking insulineee for the treatment of diabetes,则它将中断。它需要的完全匹配The patient is taking insuline for the treatment of diabetes。
但是,我还需要区分大小写的匹配项,如果文本为The patient is taking Insuline for the treatment of diabetes …