Fix regex and add javadoc