我想在Java中創建一個匹配下列字符串的模式;用逗號分隔的字符串的正則表達式
String message ="%%140911,A,140929100526,S0117.6262E03647.8107,000,067,F100,4F000100,108";
我形成的模式與字符串不匹配。我錯過了什麼? Ihis是我迄今爲止所嘗試的模式:
private static final Pattern pattern = Pattern.compile(
"(\\%\\%)"+"(\\d)," + // Id
"([AL])," + // Validity a for valid and l for invalid
"(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})," + // Date (YYMMDD)Time (HHMMSS)
"([NS])" + "(\\d{2})(\\d{2}\\.\\d+)" + "([EW])" + "(\\d{3})(\\d{2}\\.\\d+)," + //loc
"(\\d+)," + // Speed
"(\\d+)," + // Direction
"([FC])" + "(\\d{3})," + // temperature in Fahrenheit/celsius
"(\\w{8})," + // status
"(\\d+)"); // event
你想達到什麼樣的?只需用逗號分割字符串,並將其分配到不同的變量中。 – Braj 2014-10-01 10:45:36
想要將發送到服務器的消息匹配到特定模式,但也可以選擇僅分割字符串 – user3737364 2014-10-01 10:57:33