Javaの正規表現で、最長一致数量子/最短一致数量子という直前の文字の繰り返しを意味する似たような表現があります。
最長一致量子 X+ X、1 回以上を意味します。
最短一致数量子X+? X、1 回以上を意味します。
マッチングした部分を返す時に違いがあります。
最長一致量子 X+
String str = "abbbbbbbbbbbcd"
String result;
Matcher m =
Pattern.compile("a(b+)").matcher(str);
if(m.find()) {
result = m.group(1); ->"bbbbbbbbbbb"
}else{
result = null;
}
最短一致数量子X+?
String str = "abbbbbbbbbbbcd"
String result;
Matcher m =
Pattern.compile("a(b+?)").matcher(str);
if(m.find()) {
result = m.group(1); ->"b"
}else{
result = null;
}


