fork(7) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.util.regex.*;
  4. import java.util.List;
  5.  
  6. class Program {
  7. public static void main (String[] args) throws java.lang.Exception {
  8.  
  9. String subject = ".+*?[^]$(){}=!<>|:-\\";
  10. String sanitized = subject.replaceAll("[.\\+*?\\[^\\]$(){}=!<>|:-\\\\]", "\\\\$0");
  11. System.out.println(sanitized);
  12.  
  13. // Second example
  14. System.out.println("\nSecond Example in Reply to Comment");
  15. String sanit2 = "(?<=" + "/me".replaceAll("[.\\+*?\\[^\\]$(){}=!<>|:-\\\\]", "\\\\$0") + ").*";
  16. System.out.println(sanit2);
  17. Matcher m = Pattern.compile(sanit2).matcher("/me eats");
  18. System.out.println(m.find());
  19. System.out.println(m.group());
  20.  
  21.  
  22. } // end main
  23. } // end Program# your code goes here
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:-\\

Second Example in Reply to Comment
(?<=/me).*
true
 eats