私は正規表現を使用する初心者です。 と のような文字列がString1= "DELIVERY 'text1' 'text2'"ありstring2="DELIVERY 'text1'"、 を抽出したいです"text1"。このパターンでやってみた
Pattern p = Pattern.compile("^DELIVERY\\s'(.*)'");
Matcher m2 = p.matcher(string);
if (m2.find()) {
System.out.println(m2.group(1));
}
結果は次 のとおりtext1' 'text2でした:1番目の文字列と text12番目の文字列についてもこれを試しました
Pattern p = Pattern.compile("^DELIVERY\\s'(.*)'\\s'(.*)'");
Matcher m2 = p.matcher(string);
if (m2.find()) {
System.out.println(m2.group(1));
}
String1のみの結果を返します