作者CindyLinz (Cindy Wang)
看板RegExp
標題Re: [問題]請問正規表示式如何抓取這樣的字串
時間Thu Nov 20 21:09:14 2014
※ 引述《CindyLinz (Cindy Wang)》之銘言:
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.121.80.249
: ※ 文章網址: http://www.ptt.cc/bbs/RegExp/M.1415297116.A.8B5.html
: → CindyLinz: 細節說明可以看 http://perldoc.perl.org/perlre.html 11/07 02:06
: ※ 編輯: CindyLinz (112.121.80.249), 11/07/2014 02:18:42
: 推 lin1987www: 大大超強的!我本來嘗試?>去做不行...最後看懂大大答案 11/12 19:43
: → lin1987www: 可否請大大印出Debug的程序,我腦袋跑步出來結果 xd 11/12 20:14
: → CindyLinz: Debug 的程序是指...?? 11/12 23:15
: → lin1987www: 參考 http://stackoverflow.com/a/2348725/1584100 11/20 11:05
哈哈 新學到一招 use re 'debug'; ^^
可是印出來好長..
我把測試程式碼貼給你你自己印好了.. ^^|
use re 'debug';
sub f {
if( $_[0] =~ /(?<!A)A([^AB]*|A(?-1)B)B(?!B)/ ) {
print "Y\n";
} else {
print "N\n";
}
}
f('AAABBB');
f('AAABBBB');
f('AAACBBBB');
f('AAAACBBBB');
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.121.80.249
※ 文章網址: http://www.ptt.cc/bbs/RegExp/M.1416488956.A.60D.html
→ lin1987www: 感謝大大...但是我沒有可以Run Perl的環境 Q"Q 11/24 20:14
→ lin1987www: 使用貓頭鷹RegexBuddy也跑不出來Perl我不會用... 11/24 20:15
→ lin1987www: 我在Window底下 xd 11/24 20:16
推 lin1987www: 感謝 美女大大 Q"Q 11/25 04:39