Anna
Anna

Reputation: 13

Java Regex to accept anything but not angle brackets

I want a regex to be used in Java which can contain any special characters, alphabets or numbers but not < OR > (angle brackets).

I found this, ^[\<>]* but it gives

Invalid escape sequence

when used in my code.

Please help.

Upvotes: 1

Views: 1730

Answers (1)

Jobi Subramunian
Jobi Subramunian

Reputation: 146

 String regex="[^<>]*";
        Pattern p= Pattern.compile(regex);
        if(p.matcher("your input string").matches()){
            // place for your logic
        }

Upvotes: 2

Related Questions