我正在尝试从 url 中提取纬度和经度:
source: ...sensor=false¢er=-15.842208999999999%2C-48.023084&zoom=17&size=256x256&language=en&client=google-maps-frontend&signature=hbey3U4lycTNgX48asW8MODjJLM
I'm not good in regexes, so I used this regex tester (http://regexpal.com/) and coded this regex
-?\d{2}\.?\d{6}(is for JAVA )
It produces this result (who's saying it is regexpal.com):
-15.842208 ... -48.023084
So when I do it (in java):
for (Element element : newsHeadlines) {
if(element.toString().contains("https://maps.google.com")){
List<String> lista = get_matches(element.attr("content"), "-?\\d{2}\\.?\\d{6}");
}
}
public static List<String> get_matches(String s, String p) {
// returns all matches of p in s for first group in regular expression
List<String> matches = new ArrayList<String>();
Matcher m = Pattern.compile(p).matcher(s);
while(m.find()) {
matches.add(m.group(1)); //<-- Exception m.group(1) not have any results.
}
return matches;
}
我的正则表达式有什么问题?
最佳答案
关于java - 我的正则表达式有什么问题 -?\\d{2}\\.?\\d{6},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981528/