2014-01-24 78 views
0

我一直在閱讀這篇文章的第一次出現,但它並沒有解決我的問題: Regex: matching up to the first occurrence of a character匹配到一個字符

我有這個變量:

$attributes = ID=CUFF.1;Name=CG12402-RB;Note=Parial_gene 

我寫了這個腳本:

if ($attributes =~ /Name=([^;]*)/) { 
      $genename = $-[0]; 
     $name = substr($attributes, $genename); 

如果我打印$name這是輸出:Name=CG12402;Note=Parial_gene

但我想這樣我的輸出:Name=CG12402

有人能幫助我嗎?

回答

2

嘗試使用這樣的:

/(Name=[^;]+)-/ 

你原來的正則表達式/Name=([^;]*)/會後字面Name=高達;

然而捕捉任何字符,爲您提供您的正則表達式不應該產生的結果,你的例子說了。它應該捕獲:CG12402-RB

+0

謝謝你它工作! – userbio

相關問題