Part of the problem here also may be that in
Java, when you reset p to be a newly compiled object, it's reference changed, and the matcher is still pointing to the original p. In Java everything is passed by value, so the Pattern that the Matcher uses does not change when you change the value of the reference-type Pattern p. Essentially, what you are trying to do will not work, ever, and it's not because Java is broken, rather it's because your code is not the Java-way of doing things. You really need to create two Patterns and two Matchers. But you might step back even further and ask yourself, what are you really trying to do, and why? You may find that what you are trying to do can be done in a better way.