fork(3) download
  1. import java.util.regex.*;
  2.  
  3. class Demo {
  4. public static void main(String[] args) {
  5. String myString =
  6. "text KEYWORD1 text KEYWORD1 text KEYWORD2 text KEYWORD2";
  7. Pattern pattern = Pattern.compile("KEYWORD1((.(?!KEYWORD1))+?)KEYWORD2");
  8. Matcher matcher = pattern.matcher(myString);
  9. String word = "";
  10. if (matcher.find())
  11. word = matcher.group(1);
  12. System.out.println(word);
  13. }
  14. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
 text