我正在尝试使用正则表达式从字符串中删除一些单词,使用以下程序进行操作。它可以正确地删除,但只能区分大小写。如何使它不区分大小写?我在
replaceAll
方法中添加了(?1)
,但没有起作用。package com.test.java;
public class RemoveWords {
public static void main(String args[])
{
// assign some words to string
String sample ="what Is the latest news today in Europe? is there any thing special or everything is common.";
System.out.print(sample.replaceAll("( is | the |in | any )(?i)"," "));
}
}
输出:
what Is latest news today Europe? there thing special or everything common.