Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

match with regular expresion !

Status
Not open for further replies.

KeziaKristina

Programmer
Nov 1, 2002
13
ID
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top