I am new to Java. Please help me with a Java regex to match a pattern and retrieve the value. I need to match the pattern bellow:
\# someproperty=somevalue // this is a new property
\#someproperty=somevalue // this is a new property
I have to match the above patterns (which may contains spaces) and I need to retrieve "someproperty"
and "somevalue"
.
I tried with the pattern below, but it just matches only someproperty=somevalue
, without "#"
at the beginning. Please help me out.
Pattern propertyKeyPattern = Pattern.compile("^\\s*(\\S+?)\\s*=.*?");