当前位置: 代码迷 >> JavaScript >> 正则表达式!
  详细解决方案

正则表达式!

热度:389   发布时间:2012-02-19 19:43:39.0
求一个正则表达式!!!!!!!!
$AAA,022905,A,3802.8513,N,11426.0024,E,0.0,0.0,260707,4.7,W*6F
$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B
$CCC,A,3,,05,,12,,18,21,,30,,,,3.7,3.3,1.7*3F
$DDD,3,3,10,30,25,152,49,31,04,224,32*74
$EEE,26.4,M,24.9,M,37.3,M*16
$FFF,WGS   84*06
-----------------------------------
我想取出$BBB     的数据...
$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B

------解决方案--------------------
split换行,再取[1]就行。
------解决方案--------------------
<textarea id= "textarea1 ">
$AAA,022905,A,3802.8513,N,11426.0024,E,0.0,0.0,260707,4.7,W*6F
$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B
$CCC,A,3,,05,,12,,18,21,,30,,,,3.7,3.3,1.7*3F
$DDD,3,3,10,30,25,152,49,31,04,224,32*74
$EEE,26.4,M,24.9,M,37.3,M*16
$FFF,WGS 84*06
</textarea>
<script language=javascript>
var str=document.getElementById( "textarea1 ").value
var re=/^\$BBB.*?$/mg
alert(str.match(re))
</script>
------解决方案--------------------
因为这个涉及到多行,最主要是那个m
------解决方案--------------------
试一下:
\$BBB[^\$]*

//////////////////////////////////////////////
MSN:bdbox@hotmail.com请给我一个与您交流的机会!
------解决方案--------------------
var str= '\$AAA,022905,A,3802.8513,N,11426.0024,E,0.0,0.0,260707,4.7,W*6F$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B$CCC,A,3,,05,,12,,18,21,,30,,,,3.7,3.3,1.7*3F$DDD,3,3,10,30,25,152,49,31,04,224,32*74$EEE,26.4,M,24.9,M,37.3,M*16$FFF,WGS 84*06 ';
var re=/\$BBB[^\$]*/;
WL(str.match(re));//输出

//////////////////////////////////////////////
MSN:bdbox@hotmail.com请给我一个与您交流的机会!
------解决方案--------------------
<textarea id= "textarea1 ">
$AAA,022905,A,3802.8513,N,11426.0024,E,0.0,0.0,260707,4.7,W*6F
$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B 1
$CCC,A,3,,05,,12,,18,21,,30,,,,3.7,3.3,1.7*3F
$DDD,3,3,10,30,25,152,49,31,04,224,32*74
$EEE,26.4,M,24.9,M,37.3,M*16
$FFF,WGS 84*06
$BBB,022905,3802.8513,N,11426.0024,E,1,05,3.3,120.5,M,-13.9,M,,*6B 12
</textarea>
<script language=javascript>
var str=document.getElementById( "textarea1 ").value
var re=/\$BBB[^$]+(?=\$|\s)/mg
var arr;
while ((arr = re.exec(str)) != null) {
alert(arr);}