\# is not a valid regex modifier. It would technically be a way to escape a # character, IF the # meant anything significant in Java's regex. Because it doesn't, Java is just ignoring this invalidity and reading it as a # instead of throwing you an error.