in reply to minimal match regulara expression
is greedy matching: the expression tries to capture as much as possible until the last "_". Try to change it to a non greedy quantifier (+? instead of +:if ( $this_server =~ m/^(\w+)_/ ) { $this_server = $1; }
Update: Oops, I had not noticed that you actually had found the same solution by yourself (your second post), in part due to the fact that is is poorly formated. BTW, for a closing format tag, you should use a forward slash, not a back slash.if ( $this_server =~ m/^(\w+?)_/ ) { $this_server = $1; }
|
|---|