Not only does Java not allow unlimited lookbehind, it should throw an exception if you try. The fact that you do not see this exception is a mistake in itself .
In any case, you should not use lookbehind. If you want to map the value of a specific attribute, the easiest, least unpleasant approach is to map the entire attribute and use the capture group to retrieve the value. For example:
String source = "<input id = \"g\" />"; Pattern p = Pattern.compile("\\bid\\s*=\\s*\"([^\"]*)\""); Matcher m = p.matcher(source); if (m.find()) { System.out.printf("Found 'id' attribute '%s' at position %d%n", m.group(1), m.start()); }
Output:
Found 'id' attribute 'g' at position 7
Do yourself a favor and forget a little about the looks. They are complex, even if they are not buggy, and they are really not as useful as you might expect.
Alan moore
source share