V
vorticitywolfe
Alright, this is confusing me:
$string = 2340Z 4SL -ABCD PS T1203045;
if $string =~ m/(-|\+)*(AB|YZ)*(EF|CD)*\s??(PL|PS|PT)*?/g{
print $1,$2,$3,$4;
}
This works like I want it returns values for $1,$2,$3 and $4
However,
if you change it to this
$string = 2340Z 4SL PS T1203045;
It doesn't return anything for $1,$2,$3 or $4
Why?
I thought that any match followed by a " * " says that it matches 0 or
more, so if it's not matched it's undefined but the parenthesis still
"hold" it's place, i.e. $1 is still associated with the first
parenthetical match and doesn't switch to the second (AB|YZ) in this
case.
So in the end I would like this to work like this
$string = 2340Z 4SL -ABCD PS T1203045; ### print -ABCD PS
$string = 2340Z 4SL PS T1203045; ### print PS
$string = 2340Z 4SL -CD T1203045; ### print -CD
I have some logic to do all of that, but it's the regex that is
sticking me, particularly the * vs. ? vs. what is returned.
Thanks for the help in advance!
$string = 2340Z 4SL -ABCD PS T1203045;
if $string =~ m/(-|\+)*(AB|YZ)*(EF|CD)*\s??(PL|PS|PT)*?/g{
print $1,$2,$3,$4;
}
This works like I want it returns values for $1,$2,$3 and $4
However,
if you change it to this
$string = 2340Z 4SL PS T1203045;
It doesn't return anything for $1,$2,$3 or $4
Why?
I thought that any match followed by a " * " says that it matches 0 or
more, so if it's not matched it's undefined but the parenthesis still
"hold" it's place, i.e. $1 is still associated with the first
parenthetical match and doesn't switch to the second (AB|YZ) in this
case.
So in the end I would like this to work like this
$string = 2340Z 4SL -ABCD PS T1203045; ### print -ABCD PS
$string = 2340Z 4SL PS T1203045; ### print PS
$string = 2340Z 4SL -CD T1203045; ### print -CD
I have some logic to do all of that, but it's the regex that is
sticking me, particularly the * vs. ? vs. what is returned.
Thanks for the help in advance!