Perl: Extracting multiple numbers from string

perl, regex

Solution

`[` and `]` are regex meta characters, so you have to escape them

($max, $min) = $_ =~ /\[(\d+):(\d+)\]/;

The brackets are used to denote a character class: `[ ... ]` which matches the characters inside it, e.g. `[abc]` matches `a`.

Problem

Could someone help me in correcting me for the following code. I want to extract the two numbers from a input string. ``` input string [7:0] xxxx ``` I want '7' and '0' to be loaded into two variables (min and max). I am trying to achieve this by ``` my ($max, $min); ($max, $min) = $_ =~ /[(\d+):(\d+)]/; print "min: $min max $max\n"; ``` I am getting a result as ``` Use of uninitialized value in concatenation (.) or string at constraints.pl line 16, <PH> line 165. min: max: 1 ``` regards

Original source