import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\"geo\":\\{\"type\":\"Point\",\"coordinates\":\\[(?P<latitude>[^,\\]\\}]+),(?P<longitude>[\\d\\.\\-]+)";
final String string = "{\"created_at\":\"Thu Jul 16 04:46:24 +0000 2015\",\"id\":621541368599457792,\"id_str\":\"621541368599457792\",\"text\":\"k imma shower and gn \\n\\ud83d\\ude2a matthew have fun wwith your \\\"fans \\\" babe \\ud83d\\udc94\",\"source\":\"\\u003ca href=\\\"http:\\/\\/twitter.com\\/download\\/iphone\\\" rel=\\\"nofollow\\\"\\u003eTwitter for iPhone\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":2842045238,\"id_str\":\"2842045238\",\"name\":\"d-u-y-e-n\",\"screen_name\":\"_duyxnny_\",\"location\":\"\\u2708\\ufe0friverside,california - \",\"url\":\"http:\\/\\/twitter.com\\/_duyxnny_\\/status\\/610692899173302273\",\"description\":\"im ugly ...\",\"protected\":false,\"verified\":false,\"followers_count\":605,\"friends_count\":368,\"listed_count\":9,\"favourites_count\":19255,\"statuses_count\":15125,\"created_at\":\"Mon Oct 06 06:24:26 +0000 2014\",\"utc_offset\":-25200,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":true,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"3B94D9\",\"profile_background_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_background_images\\/598623992367304705\\/IsZyk_eZ.jpg\",\"profile_background_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_background_images\\/598623992367304705\\/IsZyk_eZ.jpg\",\"profile_background_tile\":true,\"profile_link_color\":\"9266CC\",\"profile_sidebar_border_color\":\"000000\",\"profile_sidebar_fill_color\":\"000000\",\"profile_text_color\":\"000000\",\"profile_use_background_image\":true,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/621199859144495105\\/G8x0fMV-_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/621199859144495105\\/G8x0fMV-_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/2842045238\\/1436912478\",\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":{\"type\":\"Point\",\"coordinates\":[33.958571,-117.434168]},\"coordinates\":{\"type\":\"Point\",\"coordinates\":[-117.434168,33.958571]},\"place\":{\"id\":\"6ba08e404aed471f\",\"url\":\"https:\\/\\/api.twitter.com\\/1.1\\/geo\\/id\\/6ba08e404aed471f.json\",\"place_type\":\"city\",\"name\":\"Riverside\",\"full_name\":\"Riverside, CA\",\"country_code\":\"US\",\"country\":\"United States\",\"bounding_box\":{\"type\":\"Polygon\",\"coordinates\":[[[-117.523867,33.85216],[-117.523867,39.79369],[-84.097028,39.79369],[-84.097028,33.85216]]]},\"attributes\":{}},\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"trends\":[],\"urls\":[],\"user_mentions\":[],\"symbols\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"filter_level\":\"low\",\"lang\":\"en\",\"timestamp_ms\":\"1437021984611\"}";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html