lehr88
lehr88

Reputation: 29

How do I use a regex in perl like this (.+) for specified string?

I am using this code:
m/MSG\[(.+)\]/

to detect any character between square brackets and coloring it using this code:

if($currentLine=~m/MSG\[(.+)\]/){  
 $p1=$1;  
 $outp="$p1";  
 $currentLine=~s/MSG\[(.+)\]/MSG[$cg$outp$crs]/g;}

The above code colors to the end of the line and doesn`t detect the close square bracket. How can I get this to only color to the close square bracket?
for example, using this code, (.+) meaning:

((\?+\s+\?+)|(\?+\s+\d+)|(\w+\s+\?+)|(\w+\s+\w+)|(\d+)|(\w+)|(\?+)|(\d+\s+\w)|(\?+\d+)|(\?+\s)|(\d\?+))  

are you understand the above code or explain for you?

Upvotes: 0

Views: 52

Answers (1)

Toto
Toto

Reputation: 91498

How about:

$currentLine =~ s/MSG\[([^\]]+)\]/MSG[$cg$1$crs]/g;

Upvotes: 1

Related Questions