0

I have been reading this post but It have not solved my problem: Regex: matching up to the first occurrence of a character

I have this variable:

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

I have written this script:

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

If I print $name this is the output: Name=CG12402;Note=Parial_gene

But I want my output like this: Name=CG12402

Can someone help me?

Community
  • 1
  • 1
userbio
  • 115
  • 3
  • 14

1 Answers1

2

Try using this:

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

Your original regex /Name=([^;]*)/ will capture any character after a literal Name= up to ;

However, for the example you provide your regex shouldn't produce the result you said it does. It should capture: CG12402-RB

fugu
  • 6,417
  • 5
  • 40
  • 75