小编Cha*_*der的帖子

如何在保留包含空格的复合表达式的同时拆分单词中的句子?

我需要在空格上拆分一个字符串,但我需要忽略一些包含空格的复合关键字.例如,我有一个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)

结果必须如下:

The
patient
is
currently
being
treated
for
Diabetes
with 
Thiazide diuretics
Run Code Online (Sandbox Code Playgroud)

怎么做 ?

java string split

2
推荐指数
1
解决办法
93
查看次数

如何在Java中区分大小写的RegEx?

我有一个私有方法,可用于使用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 …

java regex

-2
推荐指数
1
解决办法
4783
查看次数

标签 统计

java ×2

regex ×1

split ×1

string ×1