fork(1) download
  1. import java.util.regex.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. String txt = "There exists a word *random*.";
  6. // extract the word
  7. Matcher m = Pattern.compile("[*](.*?)[*]").matcher(txt);
  8. if (m.find()) {
  9. System.out.println("matches");
  10. System.out.println("->> " + m.group(0));
  11. txt = txt.replace(m.group(0), m.group(1).replaceAll(".", "*"));
  12. }
  13. System.out.println("-> " + txt);
  14. }
  15.  
  16. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
matches
->> *random*
-> There exists a word ******.