kuist
asked on
regex + price
Hi folks,
Here is some string I have to evaluate against a regex:
piece_1_Y_100_Motherboard
piece_2_Y_189_Processor
piece_7_N_0.1_OS
piece_8_N_0.1_Monitoring
The regex I use is:
ereg("piece_([0-9]+)_(Y|N) _([^_]+)_( .+)", $key, $regs)
Where:
// $regs[0] = $key = le nom de la variable au complet
// $regs[1] = position
// $regs[2] = Y ou N (inFormula)
// $regs[3] = price
// $regs[4] = Component's name
The problem I have is when the price contains a dot in it (like the last 2 string I gave above).
I only get 0
I tried changing ([^_]+) to ([0-9.]+) without luck
If someone could explain me what's wrong with this, I'd appreciate it.
Thanks.
Here is some string I have to evaluate against a regex:
piece_1_Y_100_Motherboard
piece_2_Y_189_Processor
piece_7_N_0.1_OS
piece_8_N_0.1_Monitoring
The regex I use is:
ereg("piece_([0-9]+)_(Y|N)
Where:
// $regs[0] = $key = le nom de la variable au complet
// $regs[1] = position
// $regs[2] = Y ou N (inFormula)
// $regs[3] = price
// $regs[4] = Component's name
The problem I have is when the price contains a dot in it (like the last 2 string I gave above).
I only get 0
I tried changing ([^_]+) to ([0-9.]+) without luck
If someone could explain me what's wrong with this, I'd appreciate it.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How do I access the price from ereg("piece_([0-9]+)_(Y|N) _(([0-9]+. [0-9]+)|([ 0-9]+))", $key, $regs) ??
thanks
thanks
<?php
//$msg = "piece_1_Y_100_Motherboard
$msg = "piece_7_N_0.1_OS";
if (ereg ("piece_([0-9]+)_(Y|N)_(([
echo "$regs[3] -- $regs[2] -- $regs[1]";
} else {
echo "Invalid format";
}
?>
<?php
//$msg = "piece_1_Y_100_Motherboard
$msg = "piece_7_N_0.1_OS";
if (ereg ("piece_([0-9]+)_(Y|N)_(([
echo "$regs[3] -- $regs[2] -- $regs[1]";
} else {
echo "Invalid format";
}
print "\nprice = $regs[3]\n";
?>
ASKER
the price it gives me is 0_1 instead of 0.1
any idea why ?
any idea why ?
ereg("piece_([0-9]+)_(Y|N)