$string = "hello/welcome";
我只想要「welcome」。我怎樣才能匹配在perl中使用(?:正則表達式)如下的模式
$string = "hello-welcome-to-the-world";
我想「你好,歡迎光臨」
我試試這個
print $1 if($string =~ m#(?:/|)(.*)(?:-to-)#); # got hello-welcome
print $1 if($string =~ m#(?:/)(.*)(?:-to-|)#); # got welcome
,但我不能能夠得到從單一的正則表達式所需的輸出。 請解決和解釋......
使用該(?:\w.+/)?(.*?(?=$|-to-))
,我得到的答案都是字符串
你能澄清的問題是什麼?也許顯示你的輸出相比你的預期輸出。 – kevlar1818
如果問題得到解決,請接受答案,或發佈您如何做的答案。 –