利用正则表达式提取字符串
如何在下面的字符串中:“_+2_U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_U+47563140+...
如何在下面的字符串中:
“_+2_ U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_ U+47563140+34037717+00005324m+0063611d107_*L1++_,0.000_+4_ U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_ U+47553513+34060607+00005356m+0513706d104_*L1_,0.000_+6_ U+47553363+34061758+00005692m+0525958d110_*L1_,0.000_+7_ U+47532851+34062538+00006537m+0892719d097_*L1_,0.000_+8_ U+47513555+34036646+00004864m+1723651d096_*L1++_,0.000_+9_ U+47463289+34035357+00005120m+1790136d096_*L1_,0.000_+10_ U+47462947+33953023+00005380m+2292212d111_*L1++_,0.000_+11_ U+47507774+33957622+00004876m+2520247d109_*L1_,0.000_+12_ U+47553337+33963307+00004599m+2861923d103_*L1_,0.000_+13_ U+47548966+33960215+00005976m+2822926d108_*L1++_,0.000_+14_ U+47533362+33959231+00005427m+2703549d098_*L1_,0.000_ ”
提取如下面的字符串:
2_ U+47563137+34037717+00005324m+0063611d107_*L1++
12_ U+47553337+33963307+00004599m+2861923d103_*L1
最好能直接提取到数组中:
点号 X Y Z 编码
2 47563137 34037717 00005324m L1++ 展开
“_+2_ U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_ U+47563140+34037717+00005324m+0063611d107_*L1++_,0.000_+4_ U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_ U+47553513+34060607+00005356m+0513706d104_*L1_,0.000_+6_ U+47553363+34061758+00005692m+0525958d110_*L1_,0.000_+7_ U+47532851+34062538+00006537m+0892719d097_*L1_,0.000_+8_ U+47513555+34036646+00004864m+1723651d096_*L1++_,0.000_+9_ U+47463289+34035357+00005120m+1790136d096_*L1_,0.000_+10_ U+47462947+33953023+00005380m+2292212d111_*L1++_,0.000_+11_ U+47507774+33957622+00004876m+2520247d109_*L1_,0.000_+12_ U+47553337+33963307+00004599m+2861923d103_*L1_,0.000_+13_ U+47548966+33960215+00005976m+2822926d108_*L1++_,0.000_+14_ U+47533362+33959231+00005427m+2703549d098_*L1_,0.000_ ”
提取如下面的字符串:
2_ U+47563137+34037717+00005324m+0063611d107_*L1++
12_ U+47553337+33963307+00004599m+2861923d103_*L1
最好能直接提取到数组中:
点号 X Y Z 编码
2 47563137 34037717 00005324m L1++ 展开
3个回答
展开全部
reg=/[2_ U+47563137+34037717+00005324m+0063611d107_*L1++]/g;
String result=reg.exec(把上面那段字符串贴进来);
这样就提取出来了。然后你可以用String的split方法进行分割
String arr[]=result.split(/+/);//返回一个数组
String result=reg.exec(把上面那段字符串贴进来);
这样就提取出来了。然后你可以用String的split方法进行分割
String arr[]=result.split(/+/);//返回一个数组
追问
不好意思,没有详细的介绍一下问题,*号后面的编码长度是任意变化的
“_+2_ U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_ U+47563140+34037717+00005324m+0063611d107_*F1++_,0.000_+4_ U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_ U+47553513+34060607+00005356m+0513706d104_*Q2_,0.000_+6_ U+47553363+34061758+00005692m+0525958d110_*_,0.000_+7_ U
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
# /bin/perl
$str='_+2_U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_U+47563140+34037717+00005324m+0063611d107_*L1++_,0.000_+4_U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_U+47553513+34060607+00005356m+0513706d104_*L1_,0.000_+6_U+47553363+34061758+00005692m+0525958d110_*L1_,0.000_+7_U+47532851+34062538+00006537m+0892719d097_*L1_,0.000_+8_U+47513555+34036646+00004864m+1723651d096_*L1++_,0.000_+9_U+47463289+34035357+00005120m+1790136d096_*L1_,0.000_+10_U+47462947+33953023+00005380m+2292212d111_*L1++_,0.000_+11_U+47507774+33957622+00004876m+2520247d109_*L1_,0.000_+12_U+47553337+33963307+00004599m+2861923d103_*L1_,0.000_+13_U+47548966+33960215+00005976m+2822926d108_*L1++_,0.000_+14_U+47533362+33959231+00005427m+2703549d098_*L1_,0.000_';
@array = ($str =~ m/(\d+_U\+\d+\+\d+\+\d+m\+\d+d\d+_\*L1(?:\+\+)?)/g);
$n=join "\n",@array;
print "$n\n";
我试过了,可以的。
$str='_+2_U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_U+47563140+34037717+00005324m+0063611d107_*L1++_,0.000_+4_U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_U+47553513+34060607+00005356m+0513706d104_*L1_,0.000_+6_U+47553363+34061758+00005692m+0525958d110_*L1_,0.000_+7_U+47532851+34062538+00006537m+0892719d097_*L1_,0.000_+8_U+47513555+34036646+00004864m+1723651d096_*L1++_,0.000_+9_U+47463289+34035357+00005120m+1790136d096_*L1_,0.000_+10_U+47462947+33953023+00005380m+2292212d111_*L1++_,0.000_+11_U+47507774+33957622+00004876m+2520247d109_*L1_,0.000_+12_U+47553337+33963307+00004599m+2861923d103_*L1_,0.000_+13_U+47548966+33960215+00005976m+2822926d108_*L1++_,0.000_+14_U+47533362+33959231+00005427m+2703549d098_*L1_,0.000_';
@array = ($str =~ m/(\d+_U\+\d+\+\d+\+\d+m\+\d+d\d+_\*L1(?:\+\+)?)/g);
$n=join "\n",@array;
print "$n\n";
我试过了,可以的。
追问
你的不具有代表性,看这个能提取出来么?
“_+2_ U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_ U+47563140+34037717+00005324m+0063611d107_*F1++_,0.000_+4_ U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_ U+47553513+34060607+00005356m+0513706d104_*F1_,0.000_+6_ U+47553363+34061758+00005692m+0525958d110_*F1_,0.000_+7_ U+47532851+34062538+00006537m+0892719d097_*_,0.000_+8_
追答
# /bin/perl
$str="_+2_ U+47563137+34037717+00005324m+0063611d107_*L1++_,0.000_+3_ U+47563140+34037717+00005324m+0063611d107_*F1++_,0.000_+4_ U+47564547+34058752+00004847m+0373258d099_*L1_,0.000_+5_ U+47553513+34060607+00005356m+0513706d104_*F1_,0.000_+6_ U+47553363+34061758+00005692m+0525958d110_*F1_,0.000_+7_ U+47532851+34062538+00006537m+0892719d097_*_,0.000_+8_";
@array = ($str =~ m/(\d+)_\s*U\+(\d+)\+(\d+)\+(\d+m)\+\d+d\d+_\*([LF]1(?:\+\+)?)/g);
print "点号 X Y Z 编码\n";
$m=0;
for(@array){
print "$_\t";
if(++$m == 5){
print "\n";
$m=0;
}
}
你应该好好学学正则表达式。
结果是:
点号 X Y Z 编码
2 47563137 34037717 00005324m L1++
3 47563140 34037717 00005324m F1++
4 47564547 34058752 00004847m L1
5 47553513 34060607 00005356m F1
6 47553363 34061758 00005692m F1
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-05
展开全部
string.Format("","*"); //结果:"*___"[长度为4] "_"表示一个空格
M:格式化后的长度
另外,站长团上有产品团购,便宜有保证
M:格式化后的长度
另外,站长团上有产品团购,便宜有保证
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询