Java regex case insensitivity not working

前端 未结 3 483
谎友^
谎友^ 2020-12-31 15:21

I\'m trying to remove some words in a string using regex using below program. Its removing properly but its considering only case sensitive. How to make it as case insensiti

3条回答
  •  离开以前
    2020-12-31 16:08

    I don't think you can specify case insensitive with the quick replace. Try a pattern instead. i.e:

    package com.test.java;
    
    public class RemoveWords {
    
    public static void main(String args[]) {
      // assaign some words to string
      String sample ="what Is the latest news today in Europe? is there any thing special or everything is common.";
      String regex = "( is | the |in | any )"
      System.out.print
      (
        Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(sample).replaceAll("")
      );
     }
    }
    

提交回复
热议问题