Skip to content

Instantly share code, notes, and snippets.

@kentyeh
Last active July 22, 2016 08:33
Show Gist options
  • Save kentyeh/cbd3e2f3ed8336b9ed0a to your computer and use it in GitHub Desktop.
Save kentyeh/cbd3e2f3ed8336b9ed0a to your computer and use it in GitHub Desktop.
alert complex message in html
import java.util.*;
public class Utilities {
private static final Pattern pDquote = Pattern.compile("\"");
private static final Pattern pSquote = Pattern.compile("'");
private static final Pattern pBackSlash = Pattern.compile("\\\\");
private static final Pattern pNewline = Pattern.compile("[\n\r]+");
public static String alertInner(String msg) {
return msg == null || msg.trim().isEmpty() ? "" : pNewline.matcher(
pSquote.matcher(pDquote.matcher(pBackSlash.matcher(msg).replaceAll("\\\\\\\\")).replaceAll(""")).replaceAll("\\\\'")).replaceAll("\\\\r\\\\n");
}
public static String alertInFunc(String msg) {
return msg == null || msg.trim().isEmpty() ? "" : pNewline.matcher(
pSquote.matcher(pDquote.matcher(pBackSlash.matcher(msg).replaceAll("\\\\\\\\")).replaceAll("\\\\\"")).replaceAll("\\\\'")).replaceAll("\\\\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment