473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Please help with this reg expression.

290 100+
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:

Expand|Select|Wrap|Line Numbers
  1. // Find prices - gap unit
  2. if(preg_match('#([<=then after])(day)?(month)?#', $prod->price, $matches) == 1) {
  3.   $price_gap_unit = $matches[0];
  4.   if($price_gap_unit == '') $price_gap_unit = $matches[1];
  5.    write_log("$prod->prod_id. Price_gap_unit: $price_gap_unit\r\n");
  6.    }
  7. else {
  8.   $price_gap_unit = 'none';
  9. }    
  10.  
In my log I get this:

95330. Price_gap_unit:
So, it looks like the regex is finding the match, but it is not
in the $matches[0] or $matches[1] .

Any ideas what is going wrong ?
Feb 24 '10 #1
5 1196
Dormilich
8,658 Expert Mod 8TB
no, but you can try var_dump($matches);
Feb 24 '10 #2
jeddiki
290 100+
Thanks,

I inserted that code, plus an echo to show
the contents of $prod->price.
like this:

Expand|Select|Wrap|Line Numbers
  1. if(preg_match('#([<=then after])(day)?(month)?#', $prod->price, $matches) == 1) {
  2.    $price_gap_unit = $matches[0];
  3.    if($price_gap_unit == '') $price_gap_unit = $matches[1];
  4.     write_log("$prod->prod_id. Price_gap_unit: $price_gap_unit \r\n");
  5.     echo "Prod->price: $prod->price<br>"; 
  6.     var_dump($matches);
  7.     exit;
  8.     }
  9. else {
  10.     $price_gap_unit = 'none';
  11.     }    
  12.  

Interestingly the output is:

Prod->price: $49.95
array(2) { [0]=> string(1) " " [1]=> string(1) " " }
So - I thought that if stmt would only be true if "then after" was found in the
string.

???


.
Feb 24 '10 #3
Dormilich
8,658 Expert Mod 8TB
you’re not looking for "then after" (as a string), you’re looking for one of the characters of " <=aefhnrt"
Feb 24 '10 #4
jkmyoung
2,057 Expert 2GB
Your regex is to blame. It finds the shortest match, eg the match without either day or month.
(day)?(month)?
I think you want:
((day)|(month))
Feb 24 '10 #5
jeddiki
290 100+
Yes,

I think you are right :-)

Actually, do I need the double parenthesis ?

Maybe just (day|month)? ?

Oh - tried it and I had to take out that ?

(day|month) seems to work.

Thanks for helping. :)


.
Feb 25 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jay | last post by:
PREDICATES Used as a clause. A. What does PREDICATES mean? B. What does it mean when used in a where clause? I checked BOL (Glossary) but get no explanation there. Thanks Jay
6
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily...
6
by: Buck Rogers | last post by:
Hi guys! Love your work! The below program is from K&R2, p22. ================================= #include <stdio.h> /* count digits, white space, others */ main() {
36
by: Christopher Benson-Manica | last post by:
This function is intended to print a string guaranteed to be in the form MM/DD/YYYY (assume <stdio.h> and <string.h> are included) as YYYY-MM-DD: void printdate( const char *date ) { char...
7
by: Jeff | last post by:
Hi - For my VB.NET app, I have a SQL2K database that I use to create a dataset with multiple data tables. I've created a dataview (dvReportsTo) of one of the tables, SCPMaster, and I've bound a...
30
by: Jake Forson | last post by:
Hi there, Before I notify MSFT, can someone confirm this is in fact a compiler bug (it seems pretty obvious but I'm fairly new to C#). The following code (erroneously) generates compiler error...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
7
by: vbnetdev | last post by:
My boss wants this done in a day. I would be happy with a week! Anyway, I have a dataset filled with data and need to populate an MS word chart with it when writing a report. Any tutorials or...
1
by: mohsin | last post by:
hi everyone well i m little bit confused about the use of pre an post increment infact my thinking contradict with the logic of programe lets consider an example x=5; y=x++; z=x; after the...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.