skumar
skumar

Reputation: 1015

Java Regex matching not working with spaces

I want to check the string contains ST=. there may be spaces before/after ST and =.

so i have regex match as "\\s*ST\\s*=\\w+", but it doesn't work. Any thoughts?

String REG_MATCH = "\\s*ST\\s*=\\w+";
String value =" ST= CA"

if (value.matches(REG_MATCH)){
  --matched
}

Thanks in advance.

Upvotes: 1

Views: 259

Answers (1)

anubhava
anubhava

Reputation: 785156

Include optional space before and after =:

String REG_MATCH = "\\s*ST\\s*=\\s*\\w+";

Java RegEx Demo

Upvotes: 1

Related Questions