を使用しようとしましuseTransparentBounds()
たが、期待どおりに機能しないようです(ideoneで見られるように)。次のスニペットでは、m.find()
透過的な境界が有効になっているため、一致するものが見つかると予想しました。これにより、Matcher
がその領域の境界の外側を検索できるようになりました。なぜこれが機能しないのですか?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Foo {
public static void main(String[] args) {
// match everything preceded by X
Matcher m = Pattern.compile(".*(?<=X)").matcher("Foo BarX Baz");
// limit matcher to first chars outside of normal lookahead scope
m.region(0, 4);
// matcher should still find a match because of transparent bounds
m.useTransparentBounds(true);
// this fails to find a match! why?
System.out.println("found=" + m.find());
System.out.println("result=" + m.group());
}
}
(Mac OSX MountainLionでJ2SE6(1.6.0_37-b06-434-11M3909)を使用しています)