fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. //String text = "[{\"id\": 12,\"name\":\"to\",\"gender\":\"male\"}"; // => There is a match
  11. String text = "[{\"id\": 12,\"name\":\"\",\"gender\":\"male\"}"; // => There is no match
  12. Pattern p = Pattern.compile("\"name\":\"[^\\s\"]+\"");
  13. Matcher m = p.matcher(text);
  14. if (m.find()) {
  15. System.out.println("There is a match");
  16. } else {
  17. System.out.println("There is no match");
  18. }
  19. }
  20. }
Success #stdin #stdout 0.09s 49912KB
stdin
Standard input is empty
stdout
There is no match