KeziaKristina
Programmer
I have a problem to match a string with some regular expresion. for example
i have regular expresion saved in associative arrays like this
%re=qw{
1 \$[a-z]+
2 \+
3 \=
4 [0-9]};
and i have a string like this
$str = '$s += 10'
i'm trying to match those each part of string with regular expresion on array.
i've used script like this
$len = length($str);finish = 0;
while ($len > 0)
{
foreach $keys(keys(%re))
{
$temp = $re{$keys};
while ($str =~ /$temp/)
{
$dummy .= $&;
$pointer = pos($str);
$str = substr($str,$pointer,$len - $pointer);
finish = 1;
last;
}
if( finish == 1)
{
$finish = 0;
exit;
}
}
print $dummy;
and the output is $s += 10;
the problem is if the $str = '$s =+ 10'
the output is $s += 10;
how can i have output exacly like the input... i know the problem is the string was matched sortly form keys no 1 until no 4 like regular expresion above.
how can i resolve those problem ? so i can have the ouptot exacly like the input.
Thx
i have regular expresion saved in associative arrays like this
%re=qw{
1 \$[a-z]+
2 \+
3 \=
4 [0-9]};
and i have a string like this
$str = '$s += 10'
i'm trying to match those each part of string with regular expresion on array.
i've used script like this
$len = length($str);finish = 0;
while ($len > 0)
{
foreach $keys(keys(%re))
{
$temp = $re{$keys};
while ($str =~ /$temp/)
{
$dummy .= $&;
$pointer = pos($str);
$str = substr($str,$pointer,$len - $pointer);
finish = 1;
last;
}
if( finish == 1)
{
$finish = 0;
exit;
}
}
print $dummy;
and the output is $s += 10;
the problem is if the $str = '$s =+ 10'
the output is $s += 10;
how can i have output exacly like the input... i know the problem is the string was matched sortly form keys no 1 until no 4 like regular expresion above.
how can i resolve those problem ? so i can have the ouptot exacly like the input.
Thx