简体   繁体   中英

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?

怎么样:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM