Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 8 of 8

02242010, 10:06 AM #1
 Join Date
 May 2006
 Posts
 1,683
 Thanks
 28
 Thanked 4 Times in 4 Posts
Having trouble with this regex ...
Hi,
I must have made a mistake somewhere with this one
The strings I am processing have this type of format:
" $7.00 now, then after 7 days $77.00 every 1 year"
" $4.99 now, then after 3 days $99.90 every 1 month"
"$7.00 now, then after 1 month $27.00 every 1 month"
The initial payment is easy enough but I am having problems
getting out the payment "gap_unit".
By "gap_unit", I mean the "after 7 days" or "after 1 month"
This is what I have:
PHP Code:// Find prices  gap unit
if(preg_match('#([<=then after])(day)?(month)?#', $prod>price, $matches) == 1) {
$price_gap_unit = $matches[0];
if($price_gap_unit == '') $price_gap_unit = $matches[1];
write_log("$prod>prod_id. Price_gap_unit: $price_gap_unit\r\n");
}
else {
$price_gap_unit = 'none';
}
95330. Price_gap_unit:
in the $matches[0] or $matches[1] .
Any ideas what is going wrong ?
.If you want to attract and keep more clients, then offer great customer support.
SupportFocus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
02242010, 04:26 PM
#2
 Join Date
 Dec 2005
 Location
 Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
 Posts
 7,691
 Thanks
 42
 Thanked 637 Times in 625 Posts
Test and tweak your regex here:
http://www.spaweditor.com/scripts/regex/
I tried yours and it 'aint workin.
02242010, 04:29 PM
#3
 Join Date
 May 2006
 Posts
 1,683
 Thanks
 28
 Thanked 4 Times in 4 Posts
Hi,
To try and highlight my error,
I inserted that code, plus an echo to show
the contents of $prod>price.
like this:
PHP Code:
if(preg_match('#([<=then after])(day)?(month)?#', $prod>price, $matches) == 1) {
$price_gap_unit = $matches[0];
if($price_gap_unit == '') $price_gap_unit = $matches[1];
write_log("$prod>prod_id. Price_gap_unit: $price_gap_unit \r\n");
echo "Prod>price: $prod>price<br>";
var_dump($matches);
exit;
}
else {
$price_gap_unit = 'none';
}
Interestingly the output is:
So  I thought that if stmt would only be true if "then after" was found in the string.Prod>price: $49.95
array(2) { [0]=> string(1) " " [1]=> string(1) " " }
Can anyone see where I have gone wrong ?
.
If you want to attract and keep more clients, then offer great customer support.
SupportFocus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
02242010, 05:11 PM
#4
 Join Date
 Jul 2009
 Location
 South Yorkshire, England
 Posts
 2,318
 Thanks
 6
 Thanked 304 Times in 303 Posts
Everything in parantheses is captured separately. Adjust to suit.
Code:'#\$([\d\.]+) now, then after (\d+) (daysmonth) \$([\d\.]) every (\d+) (monthyear)#'
02262010, 09:14 AM
#5
 Join Date
 May 2006
 Posts
 1,683
 Thanks
 28
 Thanked 4 Times in 4 Posts
Thanks Matt,
The problem is that the "price" string is not constant in it's
structure, so I can not use a 3in1 type of approach.
My lookbehind reg exes are working but I can not get the
lookahead one to work:
The results from the log are:PHP Code:
$prod>price = " $7.00 now, then after 7 days $77.00 every 1 year ";
// Calculate prices  gap
if(preg_match('#([?<then after])(\d) #', $prod>price, $matches) == 1) {
$price_gap = trim($matches[0]);
write_log("$prod>prod_id. Price_gap: $price_gap\r\n");
}
else {
$price_gap = 0;
}
// Calculate prices  gap unit
if(preg_match('#([?<then after])(daymonth)#', $prod>price, $matches) == 1) {
$price_gap_unit = trim($matches[0]);
write_log("$prod>prod_id. Price_gap_unit: $price_gap_unit \r\n");
}
else {
$price_gap_unit = 'none';
}
// Calculate Future price *** LOOK AHEAD ***
if(preg_match('#(\.\d)(?=every)#', $prod>price, $matches) == 1) {
$future = trim($matches[0]);
}
else {
$future = 0;
}
write_log("$prod>prod_id. Future: $future \r\n");
$pricegap_flag = $price_gap_unit[0];
write_log("$prod>prod_id. Price_gap: $price_gap, Pricegap_flag: $pricegap_flag \r\n");
if( $pricegap_flag == 'd' && $price_gap < 31) {
$price_2nd = $future;
$earn = ($price_init+$price_2nd)*($comm/100);
$totearn = ($price_init+$price_2nd+(2*$future) )*($comm/100);
}
else {
$price_2nd = 0;
$earn = $price_init*($comm/100);
$totearn = ($price_init+$price_2nd+(2*$future) )*($comm/100);
}
write_log("$prod>prod_id. Future: $future, Price_2nd: $price_2nd, Earn: $earn, Totearn: $totearn \r\n");
95330. Price_gap: 7
95330. Price_gap_unit: day
95330. Future: 0
95330. Price_gap: 7, Pricegap_flag: d
95330. Future: 0, Price_2nd: 0, Earn: 3.5, Totearn: 3.5
So, you can see from the results that the
"Price_gap", "Price_gap_unit" are getting found but the
"Future" is not being picked up.
So it looks like my lookahead is not working
Thats this one:
Can you see what I did wrong ?PHP Code:
// Calculate Future price
if(preg_match('#(\.\d)(?=every)#', $prod>price, $matches) == 1) {
$future = trim($matches[0]);
}
else {
$future = 0;
}
Thanks
.
Last edited by jeddi; 02262010 at 09:18 AM.
If you want to attract and keep more clients, then offer great customer support.
SupportFocus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
02262010, 02:24 PM
#6
 Join Date
 Jul 2009
 Location
 South Yorkshire, England
 Posts
 2,318
 Thanks
 6
 Thanked 304 Times in 303 Posts
02262010, 03:19 PM
#7
 Join Date
 May 2006
 Posts
 1,683
 Thanks
 28
 Thanked 4 Times in 4 Posts
It will take a while to go through the file
and did them out.
Even if I can use a 3in1 or a 2in1 solution,
I would still like to understand where I have gone wrong with this particular
reg expression.
Why does it not match ?Code:// Calculate Future price if(preg_match('#(\.\d)(?=every)#', $prod>price, $matches) == 1) { $future = trim($matches[0]); } else { $future = 0; }
Ahh  I think there is a ) missing isn't there ?
.
If you want to attract and keep more clients, then offer great customer support.
SupportFocus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
02262010, 04:10 PM
#8
 Join Date
 May 2006
 Posts
 1,683
 Thanks
 28
 Thanked 4 Times in 4 Posts
Matt,
I have gone 10 % through the file and found these
combinations so far:
So I think that I do need the "lookback" to every working.$167.00 every 30 days for 2 times
$199.00
$14.97 every 1 month
$97.00 every 1 year
$49.95 every 28 days
$10.00 every 30 days for 12 times
$277.00 every 30 days for 2 times
$1.00 now, then after 7 days $49.95 every 30 days for 2 times
Free for the first 3 days <br> Then $99.90 for 1 month
Free for the first 1 month <br> Then $27.00 for 1 month
There will probably be more price structures as well ...
( please see previous post as well )
.
If you want to attract and keep more clients, then offer great customer support.
SupportFocus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.