I have a String in java that is actually a JSON object. Inside the string I am trying to find a pattern matching this
"uris" : ["www.google.com", "www.yahoo.com"]
I need help in creating a pattern string to find a match for this. I have no idea of automata theory and regular expressions.
Note: the above substring will always start at "uris" and end at "]" but there can be any number of spaces in between.
You may use the following regex :
"uris".*?\]
Java ( demo )
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class RegEx {
public static void main(String[] args) {
String s = "\"uris\" : [\"www.google.com\", \"www.yahoo.com\"]";
String r = "\"uris\".*?\\]";
Pattern p = Pattern.compile(r);
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group()); //"uris" : ["www.google.com", "www.yahoo.com"]
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.