在Cookie响应中解析正则表达式

时间:2015-08-04 23:22:09

标签: java regex cookies

我有一个类似于

的cookie字符串
...1_92_37.7795%2C-122.41953_87_DT...

我希望从此字符串中获取lat / long(在本例中为37.7795,-122.41953)。到目前为止,我的正则表达式和谷歌忍者技能已经不足。有谁知道正确的正则表达式这样做?我很确定lat / long总是至少有4位小数。

1 个答案:

答案 0 :(得分:0)

快速确定问题的方法。我希望它能帮到你:

List<Double> numbers = new ArrayList<>();

Pattern pattern = Pattern.compile("-?\\d+\\.\\d+");
Matcher matcher = pattern.matcher("1_92_37.7795%2C-122.41953_87_DT");

while (matcher.find()) // jcc, sorry
    numbers.add(Double.parseDouble(matcher.group()));

System.out.println(numbers);

输出:

[37.7795, -122.41953]

下次请写您的尝试来解决此问题。