Using regex to match any character except =

前端 未结 4 1877
离开以前
离开以前 2021-01-07 17:13

I am trying to write a String validation to match any character (regular, digit and special) except =.

Here is what I have written -

    String patt         


        
4条回答
  •  隐瞒了意图╮
    2021-01-07 17:35

    First of all, you don't need a regexp. Simply call contains:

    if(str.contains("="))
        System.out.println("does not");
    else
        System.out.println("matches");
    

    The correct regexp you're looking for is just

    String patternString = "[^=]*";
    

提交回复
热议问题