正則表達式提取雙引號中的字符串
\"([^\"]*)\"
例:
<my:Control x:Name="aa" RowCount="{StaticResource RowCount}" ColumnCount="{StaticResource ColumnCount}" RowSpacing="{StaticResource RowSpacing}" >
匹配結果:
JAVA調用例:
String t = "\"world\""; String p = "\"([^\"]*)\"" ; Pattern P=Pattern.compile(p); Matcher matcher1=P.matcher(t); if(matcher1.find()) { System.out.println(matcher1.group(0)); }
代碼中通過調用group()函數來得到匹配到的結果,如下:
"world"
但是我們想要雙引號中的內容,可以對group()函數得到的結果進行一下處理,如下:
String t = "\"world\""; String p = "\"([^\"]*)\"" ; Pattern P=Pattern.compile(p); Matcher matcher1=P.matcher(t); if(matcher1.find()) { System.out.println(matcher1.group(0).replaceAll(p, "$1")); }
得到的結果便是去掉雙引號之后的結果。