我是Java新手。請幫助我使用Java正則表達式來匹配模式並檢索值。 我需要波紋管匹配的模式:Java正則表達式匹配模式
\# someproperty=somevalue // this is a new property
\#someproperty=somevalue // this is a new property
我要匹配上述模式(其可以包含空格),我需要檢索"someproperty"
和"somevalue"
。
我試着用下面的模式,但它只匹配someproperty=somevalue
,沒有"#"
在開始。請幫助我。
Pattern propertyKeyPattern = Pattern.compile("^\\s*(\\S+?)\\s*=.*?");
刪除'^'或後添加一個'#' 。 – tjameson
'#這是一個新的屬性'的一部分字符串?還是評論? –
@Rohit:這是一條評論 – Mojoy