You can use org.apache.wicket.core.util.string.JavaScriptUtils#escapeQuotes. The benefit is that it doesn't use Regex.