fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "BBC The Other [lough] The kough there are [link] [hashTag]";
  11. String p = "(\\[(?:link|hashTag|lough)])|\\p{Alnum}+";
  12. Matcher m = Pattern.compile(p).matcher(s);
  13. while (m.find()) {
  14. if (m.group(1) != null)
  15. m.appendReplacement(sb, m.group(1));
  16. else
  17. m.appendReplacement(sb, "[englishWord]");
  18. }
  19. m.appendTail(sb);
  20. System.out.println(sb);
  21. }
  22. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
[englishWord]  [englishWord] [englishWord] [lough] [englishWord] [englishWord] [englishWord] [englishWord] [link] [hashTag]