I am new to Java. I would like to write a Java regex to match a pattern and retrieve the value. I need to match the pattern below:
\# 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. What can I try next?
Pattern propertyKeyPattern = Pattern.compile("^\\s*(\\S+?)\\s*=.*?");
^or add a#after it.# this is a new propertya part of string? Or a comment??and add$to it. BTW, if you are usingMatcher.matches, then the anchors are implicit, you don't need to put them.