Hi,
so, I want to do this:
I have a string like this 'a_word digit_1 digit_2'
a_word is always required, digit_2 cannot be there without digit_1
I have a three states of string:
1 - 'a_word'
2 - 'a_word digit_1'
3 - 'a_word digit_1 digit_2'
I want to use a regular expression to catch a_word -> $1, digit_1 -> $2, digit_2 -> $3
I try to use $str =~ /^(\w+)(\s+(\d+))*(\s+(\d+))*$/;
$1 $2 $3
when string is on 1st state there is no problems.
when is 2nd $3 and $2 catch the value of digit_1.
on 3th state $2 and $3 catch the value of digit_2.
Can you advice me how to change my regexp by way that guarantee to me that if some value of digit_p is missing the relevant $x will be undef.
10q
so, I want to do this:
I have a string like this 'a_word digit_1 digit_2'
a_word is always required, digit_2 cannot be there without digit_1
I have a three states of string:
1 - 'a_word'
2 - 'a_word digit_1'
3 - 'a_word digit_1 digit_2'
I want to use a regular expression to catch a_word -> $1, digit_1 -> $2, digit_2 -> $3
I try to use $str =~ /^(\w+)(\s+(\d+))*(\s+(\d+))*$/;
$1 $2 $3
when string is on 1st state there is no problems.
when is 2nd $3 and $2 catch the value of digit_1.
on 3th state $2 and $3 catch the value of digit_2.
Can you advice me how to change my regexp by way that guarantee to me that if some value of digit_p is missing the relevant $x will be undef.
10q