发表更新几秒读完 (大约67个字)
正则表达式相关
提取中括号中间的内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| String s = "[102.8164002309, 24.9892758419], [102.8165296922, 24.9887447331], [102.8168627242, 24.9887980873], [102.8169049102, 24.9890462091], [102.816831012, 24.989382232], [102.8166749033, 24.9893820851], [102.8164002309, 24.9892758419]"; // 包含中括号 Pattern pattern = Pattern.compile("(\\[.*?])"); // 不包含中括号 Pattern pattern1 = Pattern.compile("\\[(.*?)]");
Matcher matcher = pattern.matcher(s); while (matcher.find()) { System.out.println(matcher.group(1)); } System.out.println("------------------------"); Matcher matcher2 = pattern1.matcher(s); while (matcher2.find()) { System.out.println(matcher2.group(1)); } }
|
打印结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [102.8164002309, 24.9892758419] [102.8165296922, 24.9887447331] [102.8168627242, 24.9887980873] [102.8169049102, 24.9890462091] [102.816831012, 24.989382232] [102.8166749033, 24.9893820851] [102.8164002309, 24.9892758419] ------------------------ 102.8164002309, 24.9892758419 102.8165296922, 24.9887447331 102.8168627242, 24.9887980873 102.8169049102, 24.9890462091 102.816831012, 24.989382232 102.8166749033, 24.9893820851 102.8164002309, 24.9892758419
|
You need to set install_url
to use ShareThis. Please set it in _config.yml
.