亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1279 | 回復: 3
打印 上一主題 下一主題

請教一個正則匹配的問題 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-11-15 17:29 |只看該作者 |倒序瀏覽
本帖最后由 zjpixyniannian 于 2012-11-15 17:30 編輯

我有個字符串,比如 createby=root and date=20121115 and type=insert
但是這個and的數(shù)量不定,也就是說有可能只有一個 createby=root, 也可能有多個被and 連接。

如果用split的話,我可以把這個字符串用空格分割開來,然后分別處理,如果用正則的話,該如何處理呢?

$str =~ /^((\w+)=(\w+)\S+))$/ ;

這樣可以么?但是這種括號套括號的情況,我就不不知道該怎么處理這種捕獲了。。而且,最外層括號最后捕獲的數(shù)量該怎么獲得呢??


求教了。。。。

論壇徽章:
0
2 [報告]
發(fā)表于 2012-11-15 17:50 |只看該作者
貌似沒有說清楚你想捕捉什么?看著有點亂

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [報告]
發(fā)表于 2012-11-15 18:22 |只看該作者
回復 1# zjpixyniannian

How about this to get the item and value

$ cat get_item_value.pl

use strict;
use warnings;

$_ = 'createby=root and date=20121115 and type=insert';

my $sCnt = 0;
print "string= '$_'\n";
while(m/(\S+)=(\S+)/g){
  $sCnt++;
  my ($sItem, $sValue) = ($1, $2);
  print "cnt=$sCnt, item=$sItem, value=$sValue\n";
}


$ perl get_item_value.pl
string= 'createby=root and date=20121115 and type=insert'
cnt=1, item=createby, value=root
cnt=2, item=date, value=20121115
cnt=3, item=type, value=insert


   

論壇徽章:
3
CU十二周年紀念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-12-14 14:57:19射手座
日期:2014-04-25 21:23:23
4 [報告]
發(fā)表于 2012-11-15 20:19 |只看該作者
  1. $_ = 'createby=root and date=20121115 and type=insert' ;
  2.    1 while(m/(\S+)=(\S+)(?{print "$1,$2\n"})/g)
復制代碼
利用m//g,perlre:
Similarly, for repeated m/()/g the second-best match is the match at the position one notch further in the string.
The additional state of being matched with zero-length is associated with the matched string, and is reset by each assignment to pos(). Zero-length matches at the end of the previous match are ignored during split.
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP