[英]Separating digits and numbers through Regex in java
我正在使用Java進行協調轉換APP。
我想將MGRS坐標轉換為小數,例如52SCG7250042500
或5SDG7000050000
。
我想分離或提取上述坐標,例如
52 S CG 72500 42500, 5 S DG 70000 50000...
如何使用正則表達式來做到這一點?
這是我的嘗試,但只返回數字:
String aaa = "52SCG7250013500";
Pattern p = Pattern.compile("-?\\d+");
//Pattern p1 = Pattern.compile("[a-zA-Z0-9]");
Matcher m = p.matcher(aaa);
//Matcher m1 = p1.matcher(aaa);
while (m.find()) {
System.out.println(m.group());
//System.out.println(m1.group());
}
下面的代碼正常工作
Pattern p = Pattern.compile("-?\\d+");
Pattern p1 = Pattern.compile("[a-zA-Z]");
Matcher m = p.matcher(mgrs);
Matcher m1 = p1.matcher(mgrs);
//initializing variables
while (m.find()) {
System.out.println(m.group());
}//end while
while (m1.find()) {
System.out.println(m1.group());
}//end while
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.