fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String regex = "^VAR[0-9]+=\"(?:(?![^\"]*%GH)[^\"]+|[^\"]*%GH[^\".]*\\.(?![^\"]*%GH)[^\"]*)\"$";
  12. String string = "VAR1=\"custom_var%GHsadsd.%GHsadd%Ga\"\n"
  13. + "VAR1=\"%GHasdas\"\n"
  14. + "VAR1=\"%GHasdas.random\"\n"
  15. + "VAR1=\"custom\"\n"
  16. + "VAR1=\"custom%.\"\n"
  17. + "VAR1=\"custom%Grandom\"";
  18.  
  19. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  20. Matcher matcher = pattern.matcher(string);
  21.  
  22. while (matcher.find()) {
  23. System.out.println(matcher.group(0));
  24. }
  25. }
  26. }
Success #stdin #stdout 0.07s 48124KB
stdin
Standard input is empty
stdout
VAR1="%GHasdas.random"
VAR1="custom"
VAR1="custom%."
VAR1="custom%Grandom"