Reputation: 125
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?
Upvotes: 0
Views: 2627
Reputation: 6568
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
Upvotes: 2