日期:2014-05-20  浏览次数:21122 次

请教一条政则表达式
$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74
$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*74
$GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D

我希望写一条正则,用组的方式获取上面没列的数据。格式如下:
$GPGSV,         //数据头
3,                   //一共有几条
1,                   //当前是第几条
11,                 //一共包含11组数据
然后开始,每四个逗号一组
03,03,111,00,
这是一组。分别表示:卫星号,仰角,方位角,信噪比,
每行最后一组后面的“,”就没有了。取而代之的是“*”
*后面是校验


我现在自己写的正则是这样的。可是只能匹配到最后一组。很奇怪。谁能帮我修改一下也好。
\$GPGSV,(? <lineCount> \d+),(? <currentLine> \d+),(? <StarMax> \d+),((? <Prn1> \d{0,2}),(? <Elevation1> \d{0,2}),(? <Azimuth1> \d{0,3}),(? <SNR1> \d{0,2}),*)*((? <Prn2> \d{0,2}),(? <Elevation2> \d{0,2}),(? <Azimuth2> \d{0,3}),(? <SNR2> \d{0,2}),*)*((? <Prn3> \d{0,2}),(? <Elevation3> \d{0,2}),(? <Azimuth3> \d{0,3}),(? <SNR3> \d{0,2}),*)*((? <Prn4> \d{0,2}),(? <Elevation4> \d{0,2}),(? <Azimuth4> \d{0,3}),(? <SNR4> \d{0,2}),*)*\*[\d\w]+

------解决方案--------------------
这么规则的原数据,为什么不用split( ", ")把他们自动分开到数组里面?

第3-6个值不就是你要的东西?
------解决方案--------------------
\$GPGSV,(? <lineCount> \d+),(? <currentLine> \d+),(? <StarMax> \d+),(? <Prn1> \d{0,2})?,(? <Elevation1> \d{0,2})?,(? <Azimuth1> \d{0,3})?,(? <SNR1> \d{0,2})?,(? <Prn2> \d{0,2})?,(? <Elevation2> \d{0,2})?,(? <Azimuth2> \d{0,3})?,(? <SNR2> \d{0,2})?,(? <Prn3> \d{0,2})?,(? <Elevation3> \d{0,2})?,(? <Azimuth3> \d{0,3})?,(? <SNR3> \d{0,2})?,(? <Prn4> \d{0,2})?,(? <Elevation4> \d{0,2})?,(? <Azimuth4> \d{0,3})?,(? <SNR4> \d{0,2})?\*\w+