Re: [PHP] regexp novice
Stuart Dallas" wrote: On 18 May 2012, at 14:50, Jim Giner wrote: Daft is a little harsh. :) 00:40 is just not a time value that is generally accepted. It may appear harsh, but as far as I'm concerned it is daft to make assumptions like that. You've essentially disallowed 12:nn am, but allowed 1:nn am, 2:nn am, 3:nn am, etc, because you're not validating the data in a non-ambiguous way. I have no idea what you're developing, but you're making a big assumption about the data that you're getting, which may appear reasonable to you, but to me it's daft. Nothing personal, just my opinion, which is all I have to offer. Unless I've missed something, he hasn't disallowed 12:nn am, only 00:nn. If you're going to only accept 12-hour input, this is the right thing to do. 00:nn is not a valid 12-hour representation - only times from 1:nn to 12:nn are acceptable. If you were to accept 00:nn, you'd have to also accept 13:nn-23:nn as well, for consistancy. Granted, not specifying am or pm adds a layer of ambiguity, but maybe that's not relevant for this query. For example, maybe there's also a select field that has am and pm as options. As it appears that accepting only 12-hour input is part of the brief, Jim is IMHO doing the right thing. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On Thu, May 17, 2012 at 3:37 PM, Jim Giner wrote: > ok - finally had to come up with my own regexp - and am failing. > > Trying to validate an input of a time value in the format hh:mm, wherein > I'll accept anything like the following: > hmm > hhmm > h:mm > hh:mm > > in a 12 hour format. My problem is my test is ok'ing an input of 1300. > > Here is my test: > > if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) > return true; > else > return false; > > Can someone help me correct my regexp? If the ":" separator is inserted before the regex check, the following should suffice: '/^(0?[1-9]|1[12]):([0-5][0-9])$/' Test script: http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
"Stuart Dallas" wrote in message news:aba011df-8cdf-4492-be4d-51c2b54c4...@3ft9.com... On 18 May 2012, at 14:50, Jim Giner wrote: > Daft is a little harsh. :) 00:40 is just not a time value that is > generally accepted. It may appear harsh, but as far as I'm concerned it is daft to make assumptions like that. You've essentially disallowed 12:nn am, but allowed 1:nn am, 2:nn am, 3:nn am, etc, because you're not validating the data in a non-ambiguous way. I have no idea what you're developing, but you're making a big assumption about the data that you're getting, which may appear reasonable to you, but to me it's daft. Nothing personal, just my opinion, which is all I have to offer. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ Ok - here's the use. This feature is the scheduling portion of my application. The scheduling only pertains to basically daytime hours, typically 8:00am to 6:00pm. The information is used for display purposes mostly - there is no "calculating" going on with the data. Consequently, there is no need to be all-inclusive on my allowed times since they will never be used. I just want to validate the entries to be sure that a valid time has been entered for that period of a day. Noone is going to schedule anything for a midnight hour, not even a time after 8:00pm. Therefore I can be very specific about my editing criteria and can limit the entry of data that fits within that schedule. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 2012-05-17 22:37, Jim Giner wrote: Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) return true; else return false; Can someone help me correct my regexp? /([0][1-9]|[1][0-2]|^[1-9]):[0-5][0-9]/ The third part of your alternate expressions matches "3:00" from the string "13:00" (it ignores the 1 at the beginning). Using ^ avoids this because now only one digit is allowed before the :. Bye, Andreas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 18 May 2012, at 14:50, Jim Giner wrote: > Daft is a little harsh. :) 00:40 is just not a time value that is > generally accepted. It may appear harsh, but as far as I'm concerned it is daft to make assumptions like that. You've essentially disallowed 12:nn am, but allowed 1:nn am, 2:nn am, 3:nn am, etc, because you're not validating the data in a non-ambiguous way. I have no idea what you're developing, but you're making a big assumption about the data that you're getting, which may appear reasonable to you, but to me it's daft. Nothing personal, just my opinion, which is all I have to offer. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] regexp novice
"Stuart Dallas" wrote in message news:79538829-bfc4-43a4-a413-72247b145...@3ft9.com... On 18 May 2012, at 14:41, Jim Giner wrote: > "Stuart Dallas" wrote in message > news:cc22e241-c1df-48e9-bf06-8a638a356...@3ft9.com... >> On 18 May 2012, at 14:32, Jim Giner wrote: >> >>> OK - I don't yet understand how this works, but it seems to work for >>> almost >>> all cases. The one erroneous result I get is from a value of 0040 >>> (which >>> I >>> convert to 00:40 before hitting the regexp). It comes thru as Ok. If >>> you >>> have a fix for that I'd appreciate it - otherwise I'll have to devote >>> some >>> book-time to mastering this string and come up with a fix myself. >> >> Based on your requirements, 00:40 is completely valid. Why do you think >> it >> should be invalid? >> > Don't know how you write the time, but I've never used a time of 00:40. > Yes, I realize that my shorthand time string is missing a key ingredient > of > am/pm, but 12:40 would be the time in my mind regardless of the status of > the sun. In my speccific use of this code, all times would be 'daylight' > times so 40 minutes after minute would be a) not practical and b) still > not > a recognized time in a 12-hour format. Yes - in 24-hour formats, 00:40 is > correct, but my initial post did reference my need of a 12-hour format > solution. Sounds daft to me, but they're your requirements. The "fix" is simple ( 0 <= (int) $m[1] && 12 >= (int) $m[1] ) && becomes ( 1 <= (int) $m[1] && 12 >= (int) $m[1] ) && -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/= Daft is a little harsh. :) 00:40 is just not a time value that is generally accepted. As for you patch thought - THAT is generally accepted. Works great now. Thank you. Now all I have to do is read up on this stuff so I can understand how it works. But first - golf! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
times so 40 minutes after minute would be a) not practical and b) still not I meant to say "40 minutes after MIDNIGHT". -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 18 May 2012, at 14:41, Jim Giner wrote: > "Stuart Dallas" wrote in message > news:cc22e241-c1df-48e9-bf06-8a638a356...@3ft9.com... >> On 18 May 2012, at 14:32, Jim Giner wrote: >> >>> OK - I don't yet understand how this works, but it seems to work for >>> almost >>> all cases. The one erroneous result I get is from a value of 0040 (which >>> I >>> convert to 00:40 before hitting the regexp). It comes thru as Ok. If you >>> have a fix for that I'd appreciate it - otherwise I'll have to devote some >>> book-time to mastering this string and come up with a fix myself. >> >> Based on your requirements, 00:40 is completely valid. Why do you think it >> should be invalid? >> > Don't know how you write the time, but I've never used a time of 00:40. > Yes, I realize that my shorthand time string is missing a key ingredient of > am/pm, but 12:40 would be the time in my mind regardless of the status of > the sun. In my speccific use of this code, all times would be 'daylight' > times so 40 minutes after minute would be a) not practical and b) still not > a recognized time in a 12-hour format. Yes - in 24-hour formats, 00:40 is > correct, but my initial post did reference my need of a 12-hour format > solution. Sounds daft to me, but they're your requirements. The "fix" is simple… ( 0 <= (int) $m[1] && 12 >= (int) $m[1] ) && becomes ( 1 <= (int) $m[1] && 12 >= (int) $m[1] ) && -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
"Stuart Dallas" wrote in message news:cc22e241-c1df-48e9-bf06-8a638a356...@3ft9.com... On 18 May 2012, at 14:32, Jim Giner wrote: > OK - I don't yet understand how this works, but it seems to work for > almost > all cases. The one erroneous result I get is from a value of 0040 (which > I > convert to 00:40 before hitting the regexp). It comes thru as Ok. If you > have a fix for that I'd appreciate it - otherwise I'll have to devote some > book-time to mastering this string and come up with a fix myself. Based on your requirements, 00:40 is completely valid. Why do you think it should be invalid? -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ Don't know how you write the time, but I've never used a time of 00:40. Yes, I realize that my shorthand time string is missing a key ingredient of am/pm, but 12:40 would be the time in my mind regardless of the status of the sun. In my speccific use of this code, all times would be 'daylight' times so 40 minutes after minute would be a) not practical and b) still not a recognized time in a 12-hour format. Yes - in 24-hour formats, 00:40 is correct, but my initial post did reference my need of a 12-hour format solution. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On Fri, May 18, 2012 at 7:34 PM, Stuart Dallas wrote: > Based on your requirements, 00:40 is completely valid. Why do you think it > should be invalid? 00:40 is not a valid 12-hour format. BTW I just found another non-regex approach. Its even faster. function valid_time_Shiplu2($time) { sscanf($time, "%2d%2d", $h, $m); return ($h>0 && $h<13 && $m>=0 && $m<60); } -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
Re: [PHP] regexp novice
On 18 May 2012, at 14:32, Jim Giner wrote: > OK - I don't yet understand how this works, but it seems to work for almost > all cases. The one erroneous result I get is from a value of 0040 (which I > convert to 00:40 before hitting the regexp). It comes thru as Ok. If you > have a fix for that I'd appreciate it - otherwise I'll have to devote some > book-time to mastering this string and come up with a fix myself. Based on your requirements, 00:40 is completely valid. Why do you think it should be invalid? -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] regexp novice
"Jim Lucas" wrote in message news:4fb5decc.20...@cmsws.com... > On 5/17/2012 9:52 PM, Jim Lucas wrote: >> >> How about this instead? >> >> > >> $times = array( >> '100', # valid >> '1100', # valid >> '1300', # invalid >> '01:00', # valid >> '12:59', # valid >> '00:01', # valid >> '00:25pm', # invalid >> '', # valid >> 'a00', # invalid >> '00', # invalid >> ); >> >> foreach ( $times AS $time ) >> echo "{$time} is ".(valid_date($time)?'valid':'invalid')."\n"; >> >> function valid_date($time) { >> >> if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) >> return false; >> >> preg_match('#^(?P\d{1,2}):?(?P\d{2})$#', $time, $m); >> >> if ( >> $m && >> ( 0 <= (int) $m['hour'] && 12 >= (int) $m['hour'] ) && >> ( 0 <= (int) $m['minute'] && 59 >= (int) $m['minute'] ) >> ) { >> return TRUE; >> } >> >> return false; >> >> } >> >> Let me know. >> > > I optimized it a little... > > http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.php > http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.phps > > > $times = array( > '100', # valid > '1100', # valid > '1300', # invalid > '01:00',# valid > '12:59',# valid > '00:01',# valid > '00:25pm', # invalid > '', # valid > 'a00', # invalid > '00', # invalid > ); > > foreach ( $times AS $time ) > echo "{$time} is ".(valid_time($time)?'valid':'invalid')."\n"; > > function valid_time($time) { > if ( > preg_match('#^(\d{1,2}):?(\d{2})$#', $time, $m) && > ( 0 <= (int) $m[1] && 12 >= (int) $m[1] ) && > ( 0 <= (int) $m[2] && 59 >= (int) $m[2] ) > ) { > return TRUE; > } > return FALSE; > } > OK - I don't yet understand how this works, but it seems to work for almost all cases. The one erroneous result I get is from a value of 0040 (which I convert to 00:40 before hitting the regexp). It comes thru as Ok. If you have a fix for that I'd appreciate it - otherwise I'll have to devote some book-time to mastering this string and come up with a fix myself. Thanks again!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
"Jim Lucas" wrote in message news:4fb5decc.20...@cmsws.com... > On 5/17/2012 9:52 PM, Jim Lucas wrote: >> >> How about this instead? >> >> > >> $times = array( >> '100', # valid >> '1100', # valid >> '1300', # invalid >> '01:00', # valid >> '12:59', # valid >> '00:01', # valid >> '00:25pm', # invalid >> '', # valid >> 'a00', # invalid >> '00', # invalid >> ); >> >> foreach ( $times AS $time ) >> echo "{$time} is ".(valid_date($time)?'valid':'invalid')."\n"; >> >> function valid_date($time) { >> >> if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) >> return false; >> >> preg_match('#^(?P\d{1,2}):?(?P\d{2})$#', $time, $m); >> >> if ( >> $m && >> ( 0 <= (int) $m['hour'] && 12 >= (int) $m['hour'] ) && >> ( 0 <= (int) $m['minute'] && 59 >= (int) $m['minute'] ) >> ) { >> return TRUE; >> } >> >> return false; >> >> } >> >> Let me know. >> > > I optimized it a little... > > http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.php > http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.phps > > > $times = array( > '100', # valid > '1100', # valid > '1300', # invalid > '01:00',# valid > '12:59',# valid > '00:01',# valid > '00:25pm', # invalid > '', # valid > 'a00', # invalid > '00', # invalid > ); > > foreach ( $times AS $time ) > echo "{$time} is ".(valid_time($time)?'valid':'invalid')."\n"; > > function valid_time($time) { > if ( > preg_match('#^(\d{1,2}):?(\d{2})$#', $time, $m) && > ( 0 <= (int) $m[1] && 12 >= (int) $m[1] ) && > ( 0 <= (int) $m[2] && 59 >= (int) $m[2] ) > ) { > return TRUE; > } > return FALSE; > } > I'll have to study your regexp - a lot of stuff I don't understand yet in play there. Thanks for the sample! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Jim L. I did't actually consider that wide range of time values. Here is an update. Still this can be written without help of regex. I must add one more thing that a '00:01' is invalid in 12 hour format. OP wants it to be 12-hour format. function valid_time($time){ $m = substr($time, -2); $h = (explode(':', substr($time, 0, -2))); $h = $h[0]; return (is_numeric($h) && is_numeric($m) && $h>0 && $h<13 && $m>=0 && $m<60); } See the code in action here http://ideone.com/tSQIb -- Shiplu Mokaddim Talks: http://shiplu.mokadd.im Follow: http://twitter.com/shiplu Innovation distinguishes between follower and leader -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 9:52 PM, Jim Lucas wrote: How about this instead? \d{1,2}):?(?P\d{2})$#', $time, $m); if ( $m && ( 0 <= (int) $m['hour'] && 12 >= (int) $m['hour'] ) && ( 0 <= (int) $m['minute'] && 59 >= (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. I optimized it a little... http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.php http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.phps = (int) $m[1] ) && ( 0 <= (int) $m[2] && 59 >= (int) $m[2] ) ) { return TRUE; } return FALSE; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 8:07 PM, Jim Giner wrote: "Jim Lucas" wrote in message news:4fb5b89e.8050...@cmsws.com... On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h>=0&& $h<13&& $m>=0&& $m<60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: = 0&& $hour<= 12 )&& ( $minute>= 0&& $minute<= 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas Thanks for the work you did, but I really wanted to try to solve this using the more "elegant" way, which from my readings over the last year as a new php developer, seemed to be the regexp methodology. I'm so close - it's only the 1300,1400,etc. time values that are getting by my expression. And thank you Shiplu also for your simple, but non-regexp, solution. Yes - it works and I had something similar that was just missing one more check when I decided to explore the regexp method. How about this instead? \d{1,2}):?(?P\d{2})$#', $time, $m); if ( $m && ( 0 <= (int) $m['hour'] && 12 >= (int) $m['hour'] ) && ( 0 <= (int) $m['minute'] && 59 >= (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
"Jim Lucas" wrote in message news:4fb5b89e.8050...@cmsws.com... > On 5/17/2012 1:57 PM, shiplu wrote: >> On Fri, May 18, 2012 at 2:37 AM, Jim >> Ginerwrote: >> >>> ok - finally had to come up with my own regexp - and am failing. >>> >>> Trying to validate an input of a time value in the format hh:mm, wherein >>> I'll accept anything like the following: >>> hmm >>> hhmm >>> h:mm >>> hh:mm >>> >>> in a 12 hour format. My problem is my test is ok'ing an input of 1300. >>> >>> Here is my test: >>> >>> if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) >>> return true; >>> else >>> return false; >>> >>> Can someone help me correct my regexp? >>> >>> >>> >> I can not correct your regexp. But I must tell you that trying to tweak a >> regex for hours is surely **not productive**. If you got any type of text >> processing dont always go for regular expression. This problem can be >> solved just by simple string parsing. >> Here I have done that for you. >> >> >> function valid_time($time){ >> $m = (int) substr($time, -2); >> $h = (int) substr($time, 0, -2); >> return ($h>=0&& $h<13&& $m>=0&& $m<60); >> } >> >> > > That won't work, it doesn't account for the possibility of a single digit > hour field. > > I would do something like this: > > > $times = array( > '100', # valid > '1100', # valid > '1300', # invalid > '01:00',# valid > '12:59',# valid > '00:01',# valid > '00:25pm', # invalid > '', # valid > 'a00', # invalid > '00', # invalid > ); > > foreach ( $times AS $time ) > echo "{$time} is ".(valid_date($time)?'valid':'invalid')."\n"; > > function valid_date($time) { > if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) > return false; > > if ( ( $pos = strpos($c_time, ':') ) !== false ) { > list($hour, $minute) = explode(':', $c_time, 2); > } else { > $break = (strlen($c_time) - 2); > $hour = substr($c_time, 0, $break); > $minute = substr($c_time, $break, 2); > } > $hour = (int)$hour; > $minute = (int)$minute; > > if ( strlen($c_time) <= 2 ) > return false; > > if ( > ( $hour >= 0 && $hour <= 12 ) && > ( $minute >= 0 && $minute <= 59 ) > ) { > return true; > } > return false; > } > > It seems overly complicated, but it does check and error for the various > things that I could think of for possible input. > > Give it a try and let us know. > > See it in action here. > http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php > http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps > > Jim Lucas Thanks for the work you did, but I really wanted to try to solve this using the more "elegant" way, which from my readings over the last year as a new php developer, seemed to be the regexp methodology. I'm so close - it's only the 1300,1400,etc. time values that are getting by my expression. And thank you Shiplu also for your simple, but non-regexp, solution. Yes - it works and I had something similar that was just missing one more check when I decided to explore the regexp method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h>=0&& $h<13&& $m>=0&& $m<60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: = 0 && $hour <= 12 ) && ( $minute >= 0 && $minute <= 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Thank you ! "Govinda" wrote in message news:3e5dce87-29c1-4679-ad3a-53326435f...@gmail.com... > > FWIW - I couldn't find much in the way of tutorials on the meanings of the > various chars in regexp's. this helps alot: http://www.gskinner.com/RegExr/ you can paste your pattern (needle) in the top input, and hover over each char to see what it means in grep land. Paste your haystack in the big box (input), under that, to see where all your needle will be found. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
> > FWIW - I couldn't find much in the way of tutorials on the meanings of the > various chars in regexp's. this helps alot: http://www.gskinner.com/RegExr/ you can paste your pattern (needle) in the top input, and hover over each char to see what it means in grep land. Paste your haystack in the big box (input), under that, to see where all your needle will be found. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
"Yared Hufkens" wrote in message news:4fb5667d.7020...@yahoo.de... > Try this: > /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ > > FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] > to [12]). > > > Am 17.05.2012 22:37, schrieb Jim Giner: >> ok - finally had to come up with my own regexp - and am failing. >> >> Trying to validate an input of a time value in the format hh:mm, wherein >> I'll accept anything like the following: >> hmm >> hhmm >> h:mm >> hh:mm >> >> in a 12 hour format. My problem is my test is ok'ing an input of 1300. >> >> Here is my test: >> >> if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) >> return true; >> else >> return false; >> >> Can someone help me correct my regexp? >> >> >> Nope - that didn't work. Tested it against 1900, 1300 and 13:00 and all came thru as OK. Also - I don't understand at all the following: > FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] > to [12]). I know (?) that [1-9] validates any digit from 1 to 9 - I was already using that. And your point about [1-2] doesn't make sense to me since I need to validate 10:00 which [1-2] in my usage would cause 10:00 to fail. And I don't know what ? means at all. FWIW - I couldn't find much in the way of tutorials on the meanings of the various chars in regexp's. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Try this: /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] to [12]). Am 17.05.2012 22:37, schrieb Jim Giner: > ok - finally had to come up with my own regexp - and am failing. > > Trying to validate an input of a time value in the format hh:mm, wherein > I'll accept anything like the following: > hmm > hhmm > h:mm > hh:mm > > in a 12 hour format. My problem is my test is ok'ing an input of 1300. > > Here is my test: > > if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) > return true; > else > return false; > > Can someone help me correct my regexp? > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On Fri, May 18, 2012 at 2:37 AM, Jim Giner wrote: > ok - finally had to come up with my own regexp - and am failing. > > Trying to validate an input of a time value in the format hh:mm, wherein > I'll accept anything like the following: > hmm > hhmm > h:mm > hh:mm > > in a 12 hour format. My problem is my test is ok'ing an input of 1300. > > Here is my test: > > if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) >return true; > else >return false; > > Can someone help me correct my regexp? > > > I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h>=0 && $h<13 && $m>=0 && $m<60); } -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
[PHP] regexp novice
ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) return true; else return false; Can someone help me correct my regexp? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On Fri, Oct 15, 2010 at 11:07 AM, Richard Quadling wrote: > On 15 October 2010 15:45, Andrew Ballard wrote: >> On Fri, Oct 15, 2010 at 5:52 AM, Richard Quadling >> wrote: >>> On 15 October 2010 10:16, Ford, Mike wrote: > -Original Message- > From: Andre Polykanine [mailto:an...@oire.org] > Sent: 14 October 2010 21:42 > > Hi everyone, > I hope you're doing well (haven't written here for a long time :-)). > The question is as follows: I have a regexp that would do the > following. If the string begins with "Re:", it will change the > beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the > beginning. But (attention, here it is!) if the string starts with > something like "Re[4]:", it should replace it by "Re[5]:". > Here's the code: > > $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); > if ($start=="re:") { > $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); > } elseif ($start=="re[") { > // Here $1+1 doesn't work, it returns "Re[4+1]:"! > $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", > $f['Subject']); > } else { > $subject="Re: ".$f['Subject']; > } > > I know there actually exists a way to do the numeral addition > ("Re[5]:", not "Re[4+1]:"). > How do I manage to do this? This looks like a job for the "e" modifier (see http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example #4 at http://php.net/preg_replace). Something like: $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", "'re['.(\\1+1).']:\\2'", $f['Subject']); Cheers! Mike >>> >>> Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'. >>> >>> The callback seems to be the only way I could get the regex to work. >>> >> >> How about preg_replace_callback()? >> >> Andrew >> > > Already provided an example using that : > http://news.php.net/php.general/308728 > > It was the 'e' modifier I couldn't get to work, though I suppose, as > the code is eval'd, I should have been able to do it. > > The callback just seems a LOT easier. > Sorry - I missed the callback function in there. The loop threw me off because I thought that was part of the solution rather than a test container. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On 15 October 2010 15:45, Andrew Ballard wrote: > On Fri, Oct 15, 2010 at 5:52 AM, Richard Quadling wrote: >> On 15 October 2010 10:16, Ford, Mike wrote: -Original Message- From: Andre Polykanine [mailto:an...@oire.org] Sent: 14 October 2010 21:42 Hi everyone, I hope you're doing well (haven't written here for a long time :-)). The question is as follows: I have a regexp that would do the following. If the string begins with "Re:", it will change the beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the beginning. But (attention, here it is!) if the string starts with something like "Re[4]:", it should replace it by "Re[5]:". Here's the code: $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); if ($start=="re:") { $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); } elseif ($start=="re[") { // Here $1+1 doesn't work, it returns "Re[4+1]:"! $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", $f['Subject']); } else { $subject="Re: ".$f['Subject']; } I know there actually exists a way to do the numeral addition ("Re[5]:", not "Re[4+1]:"). How do I manage to do this? >>> >>> This looks like a job for the "e" modifier (see >>> http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example >>> #4 at http://php.net/preg_replace). Something like: >>> >>> $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", >>> "'re['.(\\1+1).']:\\2'", $f['Subject']); >>> >>> Cheers! >>> >>> Mike >> >> Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'. >> >> The callback seems to be the only way I could get the regex to work. >> > > How about preg_replace_callback()? > > Andrew > Already provided an example using that : http://news.php.net/php.general/308728 It was the 'e' modifier I couldn't get to work, though I suppose, as the code is eval'd, I should have been able to do it. The callback just seems a LOT easier. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On Fri, Oct 15, 2010 at 5:52 AM, Richard Quadling wrote: > On 15 October 2010 10:16, Ford, Mike wrote: >>> -Original Message- >>> From: Andre Polykanine [mailto:an...@oire.org] >>> Sent: 14 October 2010 21:42 >>> >>> Hi everyone, >>> I hope you're doing well (haven't written here for a long time :-)). >>> The question is as follows: I have a regexp that would do the >>> following. If the string begins with "Re:", it will change the >>> beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the >>> beginning. But (attention, here it is!) if the string starts with >>> something like "Re[4]:", it should replace it by "Re[5]:". >>> Here's the code: >>> >>> $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); >>> if ($start=="re:") { >>> $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); >>> } elseif ($start=="re[") { >>> // Here $1+1 doesn't work, it returns "Re[4+1]:"! >>> $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", >>> $f['Subject']); >>> } else { >>> $subject="Re: ".$f['Subject']; >>> } >>> >>> I know there actually exists a way to do the numeral addition >>> ("Re[5]:", not "Re[4+1]:"). >>> How do I manage to do this? >> >> This looks like a job for the "e" modifier (see >> http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example >> #4 at http://php.net/preg_replace). Something like: >> >> $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", >> "'re['.(\\1+1).']:\\2'", $f['Subject']); >> >> Cheers! >> >> Mike > > Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'. > > The callback seems to be the only way I could get the regex to work. > How about preg_replace_callback()? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On 15 October 2010 10:16, Ford, Mike wrote: >> -Original Message- >> From: Andre Polykanine [mailto:an...@oire.org] >> Sent: 14 October 2010 21:42 >> >> Hi everyone, >> I hope you're doing well (haven't written here for a long time :-)). >> The question is as follows: I have a regexp that would do the >> following. If the string begins with "Re:", it will change the >> beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the >> beginning. But (attention, here it is!) if the string starts with >> something like "Re[4]:", it should replace it by "Re[5]:". >> Here's the code: >> >> $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); >> if ($start=="re:") { >> $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); >> } elseif ($start=="re[") { >> // Here $1+1 doesn't work, it returns "Re[4+1]:"! >> $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", >> $f['Subject']); >> } else { >> $subject="Re: ".$f['Subject']; >> } >> >> I know there actually exists a way to do the numeral addition >> ("Re[5]:", not "Re[4+1]:"). >> How do I manage to do this? > > This looks like a job for the "e" modifier (see > http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example #4 > at http://php.net/preg_replace). Something like: > > $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", > "'re['.(\\1+1).']:\\2'", $f['Subject']); > > Cheers! > > Mike Watch out for the missing '[1]'. This needs to become '[2]' and not '[1]'. The callback seems to be the only way I could get the regex to work. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RegExp question: how to add a number?
> -Original Message- > From: Andre Polykanine [mailto:an...@oire.org] > Sent: 14 October 2010 21:42 > > Hi everyone, > I hope you're doing well (haven't written here for a long time :-)). > The question is as follows: I have a regexp that would do the > following. If the string begins with "Re:", it will change the > beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the > beginning. But (attention, here it is!) if the string starts with > something like "Re[4]:", it should replace it by "Re[5]:". > Here's the code: > > $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); > if ($start=="re:") { > $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); > } elseif ($start=="re[") { > // Here $1+1 doesn't work, it returns "Re[4+1]:"! > $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", > $f['Subject']); > } else { > $subject="Re: ".$f['Subject']; > } > > I know there actually exists a way to do the numeral addition > ("Re[5]:", not "Re[4+1]:"). > How do I manage to do this? This looks like a job for the "e" modifier (see http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example #4 at http://php.net/preg_replace). Something like: $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", "'re['.(\\1+1).']:\\2'", $f['Subject']); Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507 City Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On 14 October 2010 21:42, Andre Polykanine wrote: > Hi everyone, > I hope you're doing well (haven't written here for a long time :-)). > The question is as follows: I have a regexp that would do the > following. If the string begins with "Re:", it will change the > beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the > beginning. But (attention, here it is!) if the string starts with > something like "Re[4]:", it should replace it by "Re[5]:". > Here's the code: > > $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); > if ($start=="re:") { > $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); > } elseif ($start=="re[") { > // Here $1+1 doesn't work, it returns "Re[4+1]:"! > $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", > $f['Subject']); > } else { > $subject="Re: ".$f['Subject']; > } > > I know there actually exists a way to do the numeral addition > ("Re[5]:", not "Re[4+1]:"). > How do I manage to do this? > Thanks! Can you adapt this ... http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp question: how to add a number?
On Thu, Oct 14, 2010 at 1:42 PM, Andre Polykanine wrote: > But (attention, here it is!) if the string starts with > something like "Re[4]:", it should replace it by "Re[5]:". > Regular expressions do not support any mathematical operations. Instead, you need to use preg_match() to extract the number inside the brackets, increment it, and build a new string using simple concatenation (.). elseif ($start=="re[") { if (preg_match('/^re\[(\d+)\](.*)/i', $f['Subject'], $matches) > 0) { $f['Subject'] = 'Re[' . ($matches[1] + 1) . ']' . $matches[2]; } else { // no closing brace -- now what? } } David
[PHP] RegExp question: how to add a number?
Hi everyone, I hope you're doing well (haven't written here for a long time :-)). The question is as follows: I have a regexp that would do the following. If the string begins with "Re:", it will change the beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the beginning. But (attention, here it is!) if the string starts with something like "Re[4]:", it should replace it by "Re[5]:". Here's the code: $start=mb_strtolower(mb_substr($f['Subject'], 0, 3)); if ($start=="re:") { $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']); } elseif ($start=="re[") { // Here $1+1 doesn't work, it returns "Re[4+1]:"! $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2", $f['Subject']); } else { $subject="Re: ".$f['Subject']; } I know there actually exists a way to do the numeral addition ("Re[5]:", not "Re[4+1]:"). How do I manage to do this? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexp questions
On Fri, 2010-05-14 at 22:01 +0200, Spud. Ivan. wrote: > > > Hi, > > > > I'm trying to insert a serialized data into mysql, but I does > mysql_real_escape_string() before inserting it. > > > > INSERT IGNORE INTO `table` (`value`) VALUES > ('a:3:{s:12:"F1";s:6:"nombre";s:11:"F2";s:5:"F3";s:16:"F4";s:10:"F5";}'); > > > > it result in > > INSERT IGNORE INTO `table` (`value`) VALUES > (\'a:3:{s:12:\"F1\";s:6:\"nombre\";s:11:\"F2\";s:5:\"F3\";s:16:\"F4\";s:10:\"F5\";}\'); > > > > and of course it's not a valid SQL sentence. > > > > Why can't I escape an SQL value with " ??? > > > > Regards. > > > > I.Lopez. > > > > > > _ > ¿Quieres conocer trucos de Windows 7? ¡Los que ya lo usan te los cuentan! > http://www.sietesunpueblodeexpertos.com/index_windows7.html It appears that you're performing the mysql_real_escape_string on the entire query, and not the variables you're using in your query, hence the single quotes that denote an SQL string being escaped. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] regexp questions
> From: spudm...@hotmail.com > To: php-general@lists.php.net > Date: Fri, 14 May 2010 22:01:09 +0200 > Subject: RE: [PHP] regexp questions > > > > > Hi, > > > > I'm trying to insert a serialized data into mysql, but I does > mysql_real_escape_string() before inserting it. > > > > INSERT IGNORE INTO `table` (`value`) VALUES > ('a:3:{s:12:"F1";s:6:"nombre";s:11:"F2";s:5:"F3";s:16:"F4";s:10:"F5";}'); > > > > it result in > > INSERT IGNORE INTO `table` (`value`) VALUES > (\'a:3:{s:12:\"F1\";s:6:\"nombre\";s:11:\"F2\";s:5:\"F3\";s:16:\"F4\";s:10:\"F5\";}\'); > > > > and of course it's not a valid SQL sentence. > > > > Why can't I escape an SQL value with " ??? > > > > Regards. > > > > I.Lopez. > > > > > > _ > ¿Quieres conocer trucos de Windows 7? ¡Los que ya lo usan te los cuentan! > http://www.sietesunpueblodeexpertos.com/index_windows7.html I'm sorry, I mistaked the subject _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352
RE: [PHP] regexp questions
Hi, I'm trying to insert a serialized data into mysql, but I does mysql_real_escape_string() before inserting it. INSERT IGNORE INTO `table` (`value`) VALUES ('a:3:{s:12:"F1";s:6:"nombre";s:11:"F2";s:5:"F3";s:16:"F4";s:10:"F5";}'); it result in INSERT IGNORE INTO `table` (`value`) VALUES (\'a:3:{s:12:\"F1\";s:6:\"nombre\";s:11:\"F2\";s:5:\"F3\";s:16:\"F4\";s:10:\"F5\";}\'); and of course it's not a valid SQL sentence. Why can't I escape an SQL value with " ??? Regards. I.Lopez. _ ¿Quieres conocer trucos de Windows 7? ¡Los que ya lo usan te los cuentan! http://www.sietesunpueblodeexpertos.com/index_windows7.html
Re: [PHP] regexp questions
On May 12, 2010, at 11:20 AM, Ashley Sheridan wrote: On Wed, 2010-05-12 at 18:23 +0200, Spud. Ivan. wrote: Subject: RE: [PHP] regexp questions From: a...@ashleysheridan.co.uk To: spudm...@hotmail.com CC: php-general@lists.php.net Date: Wed, 12 May 2010 17:11:11 +0100 On Wed, 2010-05-12 at 18:13 +0200, Spud. Ivan. wrote: Date: Tue, 11 May 2010 15:38:41 -0700 From: li...@cmsws.com To: spudm...@hotmail.com CC: php-general@lists.php.net Subject: Re: [PHP] regexp questions Spud. Ivan. wrote: I think we've not so much only with the regex, but maybe you can tell me somethin helpful ;) /Word1:<\/a><\/h4>\(script.php\">fir.*?st word.*?(.*)Word2:<\/a><\/h4>(.*)Second word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is Thanks. I.Lopez. On 05/11/2010 09:56 AM, Spud. Ivan. wrote: But it doesn't explain why my regexps work fine within php 5.1 but 5.3 Ivan. Post a regex and what you think it should match but doesn't. Again... Why don't you show us an example of what it is you are trying to match this against. Then, after that example, show us what you would like to see as the output. Then, send us a copy of the code you are trying to use to make it all happen. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare I'm sorry Jim, but as majority of regexp, I can't explain you what I want with words... I simply want to pick specific text at very specific places inside the html. I'm sending you to your email the html and regex so you can test it if you want :) Thanks. I. Lopez. _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352 It might be better to use some of the DOM functions for something like this. You can pull out specific tags and tag content as you need. It's better to rely on DOM functions for these sorts of things than using regular expressions. Thanks, Ash http://www.ashleysheridan.co.uk But If I remove tags, I can't match this specific place, because are just these tags who distinct the place where to match. I.Lopez. _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352 It depends what you need to do. If you want to match specific tags, then something like getElementsByTagName() (I believe this function exists in the set of DOM functions) would very easily grab all those tags so you can work on them. I don't see much that a regex could do here that the DOM can't handle. Thanks, Ash http://www.ashleysheridan.co.uk Dont know if you found your solution or not, but here is a good website for regexp. http://lawrence.ecorp.net/inet/samples/regexp-intro.php HTH, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexp questions
On Wed, 2010-05-12 at 18:23 +0200, Spud. Ivan. wrote: > > > > > Subject: RE: [PHP] regexp questions > From: a...@ashleysheridan.co.uk > To: spudm...@hotmail.com > CC: php-general@lists.php.net > Date: Wed, 12 May 2010 17:11:11 +0100 > > On Wed, 2010-05-12 at 18:13 +0200, Spud. Ivan. wrote: > > > > > Date: Tue, 11 May 2010 15:38:41 -0700 > > From: li...@cmsws.com > > To: spudm...@hotmail.com > > CC: php-general@lists.php.net > > Subject: Re: [PHP] regexp questions > > > > Spud. Ivan. wrote: > > > > > > I think we've not so much only with the regex, but maybe you can tell me > > > somethin helpful ;) > > > > > > /Word1:<\/a><\/h4>\( > > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > > > Thanks. > > > I.Lopez. > > > > > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > >> But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > >> > > >> Ivan. > > >> > > > > > > Post a regex and what you think it should match but doesn't. > > > > > > > > > > Again... > > > > Why don't you show us an example of what it is you are trying to match this > > against. Then, after that example, show us what you would like to see as the > > output. > > > > Then, send us a copy of the code you are trying to use to make it all > > happen. > > > > -- > > Jim Lucas > > > > "Some men are born to greatness, some achieve greatness, > > and some have greatness thrust upon them." > > > > Twelfth Night, Act II, Scene V > > by William Shakespeare > > > > > I'm sorry Jim, but as majority of regexp, I can't explain you what I want > with words... > > I simply want to pick specific text at very specific places inside the html. > > > > I'm sending you to your email the html and regex so you can test it if you > want :) > > > > Thanks. > > I. Lopez. > > > > _ > Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? > ¡Regístrate ya! > http://contactos.es.msn.com/?mtcmk=015352 > > It might be better to use some of the DOM functions for something like this. > You can pull out specific tags and tag content as you need. It's better to > rely on DOM functions for these sorts of things than using regular > expressions. > > > > > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > > > > > > > > > But If I remove tags, I can't match this specific place, because are just > these tags who distinct the place where to match. > > > > I.Lopez. > > > > > _ > Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? > ¡Regístrate ya! > http://contactos.es.msn.com/?mtcmk=015352 It depends what you need to do. If you want to match specific tags, then something like getElementsByTagName() (I believe this function exists in the set of DOM functions) would very easily grab all those tags so you can work on them. I don't see much that a regex could do here that the DOM can't handle. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] regexp questions
Subject: RE: [PHP] regexp questions From: a...@ashleysheridan.co.uk To: spudm...@hotmail.com CC: php-general@lists.php.net Date: Wed, 12 May 2010 17:11:11 +0100 On Wed, 2010-05-12 at 18:13 +0200, Spud. Ivan. wrote: > Date: Tue, 11 May 2010 15:38:41 -0700 > From: li...@cmsws.com > To: spudm...@hotmail.com > CC: php-general@lists.php.net > Subject: Re: [PHP] regexp questions > > Spud. Ivan. wrote: > > > > I think we've not so much only with the regex, but maybe you can tell me > > somethin helpful ;) > > > > /Word1:<\/a><\/h4>\( > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > Thanks. > > I.Lopez. > > > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > >> But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > >> > >> Ivan. > >> > > > > Post a regex and what you think it should match but doesn't. > > > > > > Again... > > Why don't you show us an example of what it is you are trying to match this > against. Then, after that example, show us what you would like to see as the > output. > > Then, send us a copy of the code you are trying to use to make it all happen. > > -- > Jim Lucas > > "Some men are born to greatness, some achieve greatness, > and some have greatness thrust upon them." > > Twelfth Night, Act II, Scene V > by William Shakespeare I'm sorry Jim, but as majority of regexp, I can't explain you what I want with words... I simply want to pick specific text at very specific places inside the html. I'm sending you to your email the html and regex so you can test it if you want :) Thanks. I. Lopez. _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352 It might be better to use some of the DOM functions for something like this. You can pull out specific tags and tag content as you need. It's better to rely on DOM functions for these sorts of things than using regular expressions. Thanks, Ash http://www.ashleysheridan.co.uk > But If I remove tags, I can't match this specific place, because are just these tags who distinct the place where to match. I.Lopez. _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352
RE: [PHP] regexp questions
On Wed, 2010-05-12 at 18:13 +0200, Spud. Ivan. wrote: > > > > > Date: Tue, 11 May 2010 15:38:41 -0700 > > From: li...@cmsws.com > > To: spudm...@hotmail.com > > CC: php-general@lists.php.net > > Subject: Re: [PHP] regexp questions > > > > Spud. Ivan. wrote: > > > > > > I think we've not so much only with the regex, but maybe you can tell me > > > somethin helpful ;) > > > > > > /Word1:<\/a><\/h4>\( > > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > > > Thanks. > > > I.Lopez. > > > > > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > >> But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > >> > > >> Ivan. > > >> > > > > > > Post a regex and what you think it should match but doesn't. > > > > > > > > > > Again... > > > > Why don't you show us an example of what it is you are trying to match this > > against. Then, after that example, show us what you would like to see as the > > output. > > > > Then, send us a copy of the code you are trying to use to make it all > > happen. > > > > -- > > Jim Lucas > > > > "Some men are born to greatness, some achieve greatness, > > and some have greatness thrust upon them." > > > > Twelfth Night, Act II, Scene V > > by William Shakespeare > > > > > I'm sorry Jim, but as majority of regexp, I can't explain you what I want > with words... > > I simply want to pick specific text at very specific places inside the html. > > > > I'm sending you to your email the html and regex so you can test it if you > want :) > > > > Thanks. > > I. Lopez. > > > > _ > Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? > ¡Regístrate ya! > http://contactos.es.msn.com/?mtcmk=015352 It might be better to use some of the DOM functions for something like this. You can pull out specific tags and tag content as you need. It's better to rely on DOM functions for these sorts of things than using regular expressions. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] regexp questions
> Date: Tue, 11 May 2010 15:38:41 -0700 > From: li...@cmsws.com > To: spudm...@hotmail.com > CC: php-general@lists.php.net > Subject: Re: [PHP] regexp questions > > Spud. Ivan. wrote: > > > > I think we've not so much only with the regex, but maybe you can tell me > > somethin helpful ;) > > > > /Word1:<\/a><\/h4>\( > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > Thanks. > > I.Lopez. > > > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > >> But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > >> > >> Ivan. > >> > > > > Post a regex and what you think it should match but doesn't. > > > > > > Again... > > Why don't you show us an example of what it is you are trying to match this > against. Then, after that example, show us what you would like to see as the > output. > > Then, send us a copy of the code you are trying to use to make it all happen. > > -- > Jim Lucas > > "Some men are born to greatness, some achieve greatness, > and some have greatness thrust upon them." > > Twelfth Night, Act II, Scene V > by William Shakespeare I'm sorry Jim, but as majority of regexp, I can't explain you what I want with words... I simply want to pick specific text at very specific places inside the html. I'm sending you to your email the html and regex so you can test it if you want :) Thanks. I. Lopez. _ Consejos para seducir ¿Puedes conocer gente nueva a través de Internet? ¡Regístrate ya! http://contactos.es.msn.com/?mtcmk=015352
RE: [PHP] regexp questions
> Subject: RE: [PHP] regexp questions > Date: Wed, 12 May 2010 11:11:07 +0100 > From: m.f...@leedsmet.ac.uk > To: spudm...@hotmail.com; php-general@lists.php.net > > > > > -Original Message- > > From: Spud. Ivan. [mailto:spudm...@hotmail.com] > > Sent: 11 May 2010 15:56 > > To: php-general@lists.php.net > > Subject: RE: [PHP] regexp questions > > > > > > > > hehe, but I can't find anything related to regexp. I've found > > something at http://php.net/preg_match > > Changelog > > Try searching for pcre: > > Version 5.3.2 > Upgraded bundled PCRE to version 8.00. > > Version 5.3.0 > Upgraded bundled PCRE to version 7.9. > > Version 5.2.13 > Upgraded bundled PCRE to version 7.9. > > Version 5.2.9 > Fixed bug #44336 (Improve pcre UTF-8 string matching performance). > > Version 5.2.7 > Upgraded PCRE to version 7.8 > > Version 5.2.6 > Upgraded PCRE to version 7.6 > > Version 5.2.5 > Upgraded PCRE to version 7.3 > > Version 5.2.4 > Upgraded PCRE to version 7.2 > > Version 5.2.2 > Upgraded PCRE to version 7.0 > > Version 5.2.0 > Updated PCRE to version 6.7 > > ... so it looks like between PHP 5.1 and 5.3.2 you have at least 2 major > version upgrades of the PCRE library, so the previously referenced > http://www.pcre.org/changelog.txt is more than likely what you need to be > looking at. > > Cheers! > > Mike > -- > Mike Ford, > Electronic Information Developer, Libraries and Learning Innovation, > Leeds Metropolitan University, C507, Civic Quarter Campus, > Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom > Email: m.f...@leedsmet.ac.uk > Tel: +44 113 812 4730 > > > > > > To view the terms under which this email is distributed, please go to > http://disclaimer.leedsmet.ac.uk/email.htm Thank you very much, this was very useful ;) I. Lopez. _ ¿Quieres conocer trucos de Windows 7? ¡Los que ya lo usan te los cuentan! http://www.sietesunpueblodeexpertos.com/index_windows7.html
RE: [PHP] regexp questions
> -Original Message- > From: Spud. Ivan. [mailto:spudm...@hotmail.com] > Sent: 11 May 2010 15:56 > To: php-general@lists.php.net > Subject: RE: [PHP] regexp questions > > > > hehe, but I can't find anything related to regexp. I've found > something at http://php.net/preg_match > Changelog Try searching for pcre: Version 5.3.2 Upgraded bundled PCRE to version 8.00. Version 5.3.0 Upgraded bundled PCRE to version 7.9. Version 5.2.13 Upgraded bundled PCRE to version 7.9. Version 5.2.9 Fixed bug #44336 (Improve pcre UTF-8 string matching performance). Version 5.2.7 Upgraded PCRE to version 7.8 Version 5.2.6 Upgraded PCRE to version 7.6 Version 5.2.5 Upgraded PCRE to version 7.3 Version 5.2.4 Upgraded PCRE to version 7.2 Version 5.2.2 Upgraded PCRE to version 7.0 Version 5.2.0 Updated PCRE to version 6.7 ... so it looks like between PHP 5.1 and 5.3.2 you have at least 2 major version upgrades of the PCRE library, so the previously referenced http://www.pcre.org/changelog.txt is more than likely what you need to be looking at. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp questions
Spud. Ivan. wrote: > > I think we've not so much only with the regex, but maybe you can tell me > somethin helpful ;) > > /Word1:<\/a><\/h4>\( href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > Thanks. > I.Lopez. > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: >> But it doesn't explain why my regexps work fine within php 5.1 but 5.3 >> >> Ivan. >> > > Post a regex and what you think it should match but doesn't. > > Again... Why don't you show us an example of what it is you are trying to match this against. Then, after that example, show us what you would like to see as the output. Then, send us a copy of the code you are trying to use to make it all happen. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexp questions
On Tue, 2010-05-11 at 23:48 +0200, Spud. Ivan. wrote: > > > > > From: a...@ashleysheridan.co.uk > > To: spudm...@hotmail.com > > CC: php-general@lists.php.net > > Date: Tue, 11 May 2010 21:43:54 +0100 > > Subject: RE: [PHP] regexp questions > > > > On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote: > > > > > > > > I think we've not so much only with the regex, but maybe you can tell me > > > somethin helpful ;) > > > > > > /Word1:<\/a><\/h4>\( > > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > > > Thanks. > > > I.Lopez. > > > > > > >>>>>> > > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > > > > > > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > > > > > > > Ivan. > > > > > > > > > > Post a regex and what you think it should match but doesn't. > > > > > > > > > -- > > > Thanks! > > > -Shawn > > > http://www.spidean.com > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > _ > > > Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! > > > http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx > > > > > > What are you trying to match the regex against? > > > > Also, I've noticed you've used a lot of periods (.) where it looks like > > you intended a literal period to be matched. In regular expressions, > > periods match any character expect the newline, so "www.thiswebsite.com" > > would also match the string "www_thiswebsite_com". > > > > > > Ps, please try not to top post, as it disrupts the zen flow of the > > list! :) > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > > > > > Ok I'm sorry for top posting ;) > > > > Sure, I know that . match any character, but only one and It doesn't matter > to me if it's . or _ , it's ok I think. > > > > The problem is that if I test it in a small string, it works, but if I take > the 30kb html source, it only works with php versions older than 5.2 > > So, I think you wan't not to test the regexp within the original file, (or > yes? :) ) > > > > I.Lopez. > > > > _ > Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más! > http://www.imaginemobile.es Is it possible that you're running out of memory for this script? Increase the memory a script can use in php.ini to see if this helps. If that doesn't, can you determine the exact maximum filesize you can process with this regular expression? It could be you've found a bug in the regex parser perhaps? Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] regexp questions
> From: a...@ashleysheridan.co.uk > To: spudm...@hotmail.com > CC: php-general@lists.php.net > Date: Tue, 11 May 2010 21:43:54 +0100 > Subject: RE: [PHP] regexp questions > > On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote: > > > > > I think we've not so much only with the regex, but maybe you can tell me > > somethin helpful ;) > > > > /Word1:<\/a><\/h4>\( > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > > > Thanks. > > I.Lopez. > > > > >>>>>> > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > > > > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > > > > > Ivan. > > > > > > > Post a regex and what you think it should match but doesn't. > > > > > > -- > > Thanks! > > -Shawn > > http://www.spidean.com > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > _ > > Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! > > http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx > > > What are you trying to match the regex against? > > Also, I've noticed you've used a lot of periods (.) where it looks like > you intended a literal period to be matched. In regular expressions, > periods match any character expect the newline, so "www.thiswebsite.com" > would also match the string "www_thiswebsite_com". > > > Ps, please try not to top post, as it disrupts the zen flow of the > list! :) > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > Ok I'm sorry for top posting ;) Sure, I know that . match any character, but only one and It doesn't matter to me if it's . or _ , it's ok I think. The problem is that if I test it in a small string, it works, but if I take the 30kb html source, it only works with php versions older than 5.2 So, I think you wan't not to test the regexp within the original file, (or yes? :) ) I.Lopez. _ Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más! http://www.imaginemobile.es
RE: [PHP] regexp questions
On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote: > > I think we've not so much only with the regex, but maybe you can tell me > somethin helpful ;) > > /Word1:<\/a><\/h4>\( href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st > word.*?(.*)Word2:<\/a><\/h4>(.*)Second > word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is > > Thanks. > I.Lopez. > > >> > On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > > > Ivan. > > > > Post a regex and what you think it should match but doesn't. > > > -- > Thanks! > -Shawn > http://www.spidean.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > _ > Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! > http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx What are you trying to match the regex against? Also, I've noticed you've used a lot of periods (.) where it looks like you intended a literal period to be matched. In regular expressions, periods match any character expect the newline, so "www.thiswebsite.com" would also match the string "www_thiswebsite_com". Ps, please try not to top post, as it disrupts the zen flow of the list! :) Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] regexp questions
I think we've not so much only with the regex, but maybe you can tell me somethin helpful ;) /Word1:<\/a><\/h4>\(fir.*?st word.*?(.*)Word2:<\/a><\/h4>(.*)Second word:<\/a><\/h4>(.*)Word3:<\/a><\/h4>(.*)rd word/is Thanks. I.Lopez. >> On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > Ivan. > Post a regex and what you think it should match but doesn't. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx
Re: [PHP] regexp questions
On 05/11/2010 09:56 AM, Spud. Ivan. wrote: > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3 > > Ivan. > Post a regex and what you think it should match but doesn't. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexp questions
hehe, but I can't find anything related to regexp. I've found something at http://php.net/preg_match Changelog Version Description 5.2.2 Named subpatterns now accept the syntax (?) and (?'name') as well as (?P). Previous versions accepted only (?P). 4.3.3 The offset parameter was added 4.3.0 The PREG_OFFSET_CAPTURE flag was added 4.3.0 The flags parameter was added But it doesn't explain why my regexps work fine within php 5.1 but 5.3 Ivan. >>>>>>>>> > -Original Message- > From: Spud. Ivan. [mailto:spudm...@hotmail.com] > Sent: 11 May 2010 01:25 > To: php-general@lists.php.net > Subject: RE: [PHP] regexp questions > > > Is there any place where to read the changelog or something? Um, you mean, like, http://php.net/changelog ?? ;) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 _ Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx
RE: [PHP] regexp questions
> -Original Message- > From: Spud. Ivan. [mailto:spudm...@hotmail.com] > Sent: 11 May 2010 01:25 > To: php-general@lists.php.net > Subject: RE: [PHP] regexp questions > > > Is there any place where to read the changelog or something? Um, you mean, like, http://php.net/changelog ?? ;) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexp questions
Is there any place where to read the changelog or something? Thanks. >>> For example, the following regex doesn't work. return (bool) preg_match('/^[\pL\pN\pZ\p{Pc}\p{Pd}\p{Po}]++$/uD', (string) $str); Shiplu Mokadd.im _ Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya! http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx
Re: [PHP] regexp questions
For example, the following regex doesn't work. return (bool) preg_match('/^[\pL\pN\pZ\p{Pc}\p{Pd}\p{Po}]++$/uD', (string) $str); Shiplu Mokadd.im My talks, http://talk.cmyweb.net Follow me, http://twitter.com/shiplu SUST Programmers, http://groups.google.com/group/p2psust Innovation distinguishes bet ... ... (ask Steve Jobs the rest -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regexp questions
Hi, I've recently changed from php 5.1 to 5.3.2 and I'm havong problems with preg_match, because the same regular expressions used in php 5.1 are not matching anything in 5.3.2. There are any significant changes that I should know? I've been searching but I haven't found anything. Thanks. I.Lopez. _ Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info http://www.vivelive.com/hotmail-la-gente-de-hoy/index.html?multiaccount
Re: [PHP] Regexp and Arrays
I think part of the problem may lie in the use of variables in regular expressions. I am trying to use the perl-style preg_match(), but the regular expression values that it checks on each iteration of the foreach loop checks for a different value (hence, the use of a variable). On Sat, Jan 2, 2010 at 1:19 PM, shiplu wrote: > There can be a problem. But do you see a problem?? if yes. what is it? > May be we can find the solution. > > -- > Shiplu Mokaddim > My talks, http://talk.cmyweb.net > Follow me, http://twitter.com/shiplu > SUST Programmers, http://groups.google.com/group/p2psust > Innovation distinguishes bet ... ... (ask Steve Jobs the rest) >
Re: [PHP] Regexp and Arrays
On a quick glance I don't think you are doing the casting correctly. For example, you have stuff like: (string) $string; and (string) $key; (int) $val; and (int) $length_value = $match[1]; and the casted value is not being saved anywhere. I believe it should be something like $string = (string) $string; in order to assign the casted value back to the variable. In the third example, you probably meant $length_value = (int) $match[1]; On Jan 2, 2010, at 1:09 PM, Allen McCabe wrote: > I have been plauged for a few days by this, can anyone see a problem with > this function?? > > function printByType($string, $mode) > { > (string) $string; > $lengths = array( >'VARCHAR' => 10 >, 'TINYINT' => 1 >, 'TEXT' => 10 >, 'DATE' => 7 >, 'SMALLINT' => 1 >, 'MEDIUMINT' => 2 >, 'INT' => 2 >, 'BIGINT' => 3 >, 'FLOAT' => 4 >, 'DOUBLE' => 4 >, 'DECIMAL' => 4 >, 'DATETIME' => 10 >, 'TIMESTAMP' => 10 >, 'TIME' => 7 >, 'YEAR' => 4 >, 'CHAR' => 7 >, 'TINYBLOB' => 10 >, 'TINYTEXT' => 10 >, 'BLOB' => 10 >, 'MEDIUMBLOB' => 10 >, 'MEDIUMTEXT' => 10 >, 'LONGBLOB' => 10 >, 'LONGTEXT' => 10 >, 'ENUM' => 5 >, 'SET' => 5 >, 'BIT' => 2 >, 'BOOL' => 1 >, 'BINARY' => 10 >, 'VARBINARY' => 10); > $types = array( >'VARCHAR' => 'text' >, 'TINYINT' => 'text' >, 'TEXT' => 'textarea' >, 'DATE' => 'text' >, 'SMALLINT' => 'text' >, 'MEDIUMINT' => 'text' >, 'INT' => 'text' >, 'BIGINT' => 'text' >, 'FLOAT' => 'text' >, 'DOUBLE' => 'text' >, 'DECIMAL' => 'text' >, 'DATETIME' => 'text' >, 'TIMESTAMP' => 'text' >, 'TIME' => 'text' >, 'YEAR' => 'text' >, 'CHAR' => 'text' >, 'TINYBLOB' => 'textarea' >, 'TINYTEXT' => 'textarea' >, 'BLOB' => 'textarea' >, 'MEDIUMBLOB' => 'textarea' >, 'MEDIUMTEXT' => 'textarea' >, 'LONGBLOB' => 'textarea' >, 'LONGTEXT' => 'textarea' >, 'ENUM' => 'text' >, 'SET' => 'text' >, 'BIT' => 'text' >, 'BOOL' => 'text' >, 'BINARY' => 'text' >, 'VARBINARY' => 'text'); > > switch ($mode) > { > case 'INPUT_LENGTH': >foreach ($lengths as $key => $val) >{ > (string) $key; > (int) $val; > > // DETERMINE LENGTH VALUE eg. int(6) GETS 6 > preg_match('#\((.*?)\)#', $string, $match); > (int) $length_value = $match[1]; > > // SEARCH > $regex = "/" . strtolower($key) . "/i"; > $found = preg_match($regex, $string); > > if ($found !== false) > { > // DETERMINE ADD INTEGER eg. If the length_value is long enough, > determine number to increase html input length > switch ($length_value) > { > case ($length_value <= 7): >return $length_value; > break; > case ($length_value > 7 && $length_value < 15): >return $val += ($length_value/2); > break; > case ($length_value > 14 && $length_value < 101): >$result = ($length_value / 5); >$divide = ceil($result); >return $val += $divide; > break; > case ($length_value > 100): >return 40; > break; > default: >return 7; > break; > } > return $val; > } > else > { > return 7; // default value > } >} > break; > > case 'INPUT_TYPE': > >foreach ($types as $key => $val) >{ > (string) $val; > (string) $key; > > // SEARCH > $regex = "/" . strtolower($key) . "/i"; > $found = preg_match($regex, $string); > > if ($found === false) > { > return 'text'; // default value > } > else > { > return $val; > } >} > break; > } > > } // END function printByType() -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp and Arrays
There can be a problem. But do you see a problem?? if yes. what is it? May be we can find the solution. -- Shiplu Mokaddim My talks, http://talk.cmyweb.net Follow me, http://twitter.com/shiplu SUST Programmers, http://groups.google.com/group/p2psust Innovation distinguishes bet ... ... (ask Steve Jobs the rest) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regexp and Arrays
I have been plauged for a few days by this, can anyone see a problem with this function?? function printByType($string, $mode) { (string) $string; $lengths = array( 'VARCHAR' => 10 , 'TINYINT' => 1 , 'TEXT' => 10 , 'DATE' => 7 , 'SMALLINT' => 1 , 'MEDIUMINT' => 2 , 'INT' => 2 , 'BIGINT' => 3 , 'FLOAT' => 4 , 'DOUBLE' => 4 , 'DECIMAL' => 4 , 'DATETIME' => 10 , 'TIMESTAMP' => 10 , 'TIME' => 7 , 'YEAR' => 4 , 'CHAR' => 7 , 'TINYBLOB' => 10 , 'TINYTEXT' => 10 , 'BLOB' => 10 , 'MEDIUMBLOB' => 10 , 'MEDIUMTEXT' => 10 , 'LONGBLOB' => 10 , 'LONGTEXT' => 10 , 'ENUM' => 5 , 'SET' => 5 , 'BIT' => 2 , 'BOOL' => 1 , 'BINARY' => 10 , 'VARBINARY' => 10); $types = array( 'VARCHAR' => 'text' , 'TINYINT' => 'text' , 'TEXT' => 'textarea' , 'DATE' => 'text' , 'SMALLINT' => 'text' , 'MEDIUMINT' => 'text' , 'INT' => 'text' , 'BIGINT' => 'text' , 'FLOAT' => 'text' , 'DOUBLE' => 'text' , 'DECIMAL' => 'text' , 'DATETIME' => 'text' , 'TIMESTAMP' => 'text' , 'TIME' => 'text' , 'YEAR' => 'text' , 'CHAR' => 'text' , 'TINYBLOB' => 'textarea' , 'TINYTEXT' => 'textarea' , 'BLOB' => 'textarea' , 'MEDIUMBLOB' => 'textarea' , 'MEDIUMTEXT' => 'textarea' , 'LONGBLOB' => 'textarea' , 'LONGTEXT' => 'textarea' , 'ENUM' => 'text' , 'SET' => 'text' , 'BIT' => 'text' , 'BOOL' => 'text' , 'BINARY' => 'text' , 'VARBINARY' => 'text'); switch ($mode) { case 'INPUT_LENGTH': foreach ($lengths as $key => $val) { (string) $key; (int) $val; // DETERMINE LENGTH VALUE eg. int(6) GETS 6 preg_match('#\((.*?)\)#', $string, $match); (int) $length_value = $match[1]; // SEARCH $regex = "/" . strtolower($key) . "/i"; $found = preg_match($regex, $string); if ($found !== false) { // DETERMINE ADD INTEGER eg. If the length_value is long enough, determine number to increase html input length switch ($length_value) { case ($length_value <= 7): return $length_value; break; case ($length_value > 7 && $length_value < 15): return $val += ($length_value/2); break; case ($length_value > 14 && $length_value < 101): $result = ($length_value / 5); $divide = ceil($result); return $val += $divide; break; case ($length_value > 100): return 40; break; default: return 7; break; } return $val; } else { return 7; // default value } } break; case 'INPUT_TYPE': foreach ($types as $key => $val) { (string) $val; (string) $key; // SEARCH $regex = "/" . strtolower($key) . "/i"; $found = preg_match($regex, $string); if ($found === false) { return 'text'; // default value } else { return $val; } } break; } } // END function printByType()
Re: [PHP] Regexp to get paramname
> eregi(); That would be your first mistake. The preg_* functions are better. -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regexp to get paramname
Hi, I have these lines to get parameters' name to $regs, but I always get the first one twice. What do I do wrong? $sql = 'select * from hotsys where ALREND=:alrend and SYSKOD=:syskod'; eregi('(:[a-z,A-Z,0-9]+)', $sql, $regs); Thanks, SanTa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RegExp
I'm not trying to pre-populate the text area. I just want to get the input from the user and make sure he can only insert chars that I allow. The only char I have a problem with is the " (Quote). If I enter a " into the text area the regexp bellow does not allow it in. preg_match("/^[à-úA-Za-z0-9_():,@\/\.\s\"- ]*$/i",$FieldValue) - Fails preg_match("/^[à-úA-Za-z0-9_():,@\/\.\s\\"- ]*$/i",$FieldValue) (This one gives a php error cause the \\" closes the opening ") preg_match('/^[א-תA-Za-z0-9_():,@\/\.\s"- ]*$/i',$FieldValue) - Fails preg_match('/^[א-תA-Za-z0-9_():,@\/\.\s\"- ]*$/i',$FieldValue) - Fails preg_match('/^[א-תA-Za-z0-9_():,@\/\.\s\\"- ]*$/i',$FieldValue) - Fails So how can I allow a quote (") to be a valid char? thanks berber -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Saturday, December 16, 2006 3:55 AM To: WeberSites LTD Cc: php-general@lists.php.net Subject: Re: [PHP] RegExp On Thu, December 14, 2006 11:47 pm, WeberSites LTD wrote: > I'm trying to limit the text someone can submit in a text area with : > > > Code: > if(!preg_match("/^[à-úA-Za-z0-9_():,@\/\.\s\-\" ]*$/i",$FieldValue)) { > > } > > > It works well but I'm having problems with the " (double quote). > If there is a double quote (") it fails. Fails in what way? Are you sure you are remembering to do http://php.net/htmlentities on the data you send out for the TEXTAREA to pre-populate it? Does PCRE need " escaped inside the [] bit? I think not, but I suppose \\" instead of \" couldn't hurt. You may also want to move the - to the end of [] character set and lose the \, just to keep it simpler. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp
On Thu, December 14, 2006 11:47 pm, WeberSites LTD wrote: > I'm trying to limit the text someone can submit in a text area with : > > > Code: > if(!preg_match("/^[à-úA-Za-z0-9_():,@\/\.\s\-\" ]*$/i",$FieldValue)) { > > } > > > It works well but I'm having problems with the " (double quote). > If there is a double quote (") it fails. Fails in what way? Are you sure you are remembering to do http://php.net/htmlentities on the data you send out for the TEXTAREA to pre-populate it? Does PCRE need " escaped inside the [] bit? I think not, but I suppose \\" instead of \" couldn't hurt. You may also want to move the - to the end of [] character set and lose the \, just to keep it simpler. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp
WeberSites LTD wrote: > I'm trying to limit the text someone can submit in a text area with : > > > Code: > if(!preg_match("/^[א-תA-Za-z0-9_():,@\/\.\s\-\" ]*$/i",$FieldValue)) { ^^ ^-- no need for the space given you already have '\s' ^^ ^^--- these brackets need escaping > avoid sticking your regexps in double quotes strings - you just end up giving yourself an escaping headache. what is exactly is the goal of the 'limit' you are imposing - wouldn't something like strip_tags() be much easier? > } > > > It works well but I'm having problems with the " (double quote). > If there is a double quote (") it fails. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RegExp
I'm trying to limit the text someone can submit in a text area with : Code: if(!preg_match("/^[א-תA-Za-z0-9_():,@\/\.\s\-\" ]*$/i",$FieldValue)) { } It works well but I'm having problems with the " (double quote). If there is a double quote (") it fails.
Re: [PHP] RegExp for preg_split()
LOL It's interesting that you've taked your time and build that 'summation', maybe the only thing is missing is the code itself ;) Now, because you didn't add it, I had to check the different versions, and I agree with John Hicks, his suggestion seems to be the best one. tedd wrote: A summation of entries. http://xn--ovg.com/a/parse.php neat! tedd -- Atentamente, J. Rafael Salazar Magaña Innox - Innovación Inteligente Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE http://www.innox.com.mx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp for preg_split()
Hi: A summation of entries. http://xn--ovg.com/a/parse.php neat! tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RegExp for preg_split()
Thanks, But this example seems to be short and does the job : Unless I'm missing something? thanks -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Saturday, April 29, 2006 10:29 AM To: Weber Sites LTD Cc: php-general@lists.php.net Subject: Re: [PHP] RegExp for preg_split() On Fri, April 28, 2006 11:16 am, Weber Sites LTD wrote: > I'm looking for the RegExp that will split a search string into search > keywords. > while taking " " into account. > > From what I managed to find I can get all of the words into an array > but I would like all of the words inside " " to be in the same array > cell. I'd be pretty surprised if searching for things like: PHP simple search input quotes and things like that didn't turn up some solutions... You might have to search in specific forums rather than a general Google, but. Here's one crude solution though: Note that invalid input such as unbalanced quote marks will mess this up big-time, probably... But maybe that's just as well... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp for preg_split()
On Fri, April 28, 2006 11:16 am, Weber Sites LTD wrote: > I'm looking for the RegExp that will split a search string into search > keywords. > while taking " " into account. > > From what I managed to find I can get all of the words into an array > but I > would > like all of the words inside " " to be in the same array cell. I'd be pretty surprised if searching for things like: PHP simple search input quotes and things like that didn't turn up some solutions... You might have to search in specific forums rather than a general Google, but. Here's one crude solution though: Note that invalid input such as unbalanced quote marks will mess this up big-time, probably... But maybe that's just as well... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp for preg_split()
Weber Sites LTD wrote: Hi I'm looking for the RegExp that will split a search string into search keywords. while taking " " into account. From what I managed to find I can get all of the words into an array but I would like all of the words inside " " to be in the same array cell. You want to use preg_match_all, not preg_split: $String = 'Medaillons, Listels, "custom stuff", "more things", entryway, accents, showplace'; $MyRegEx = '/"[^"]+"|[^"\s,]+/'; preg_match_all($MyRegEx, $String, $Tokens); echo ''; var_dump($Tokens); produces: array(1) { [0]=> array(7) { [0]=> string(10) "Medaillons" [1]=> string(7) "Listels" [2]=> string(14) ""custom stuff"" [3]=> string(13) ""more things"" [4]=> string(8) "entryway" [5]=> string(7) "accents" [6]=> string(9) "showplace" } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RegExp for preg_split()
This is part of what I need. You found all of the phrases (e.g. all of the strings inside " ") But I also need all of the words that are not inside " ". thanks -Original Message- From: tedd [mailto:[EMAIL PROTECTED] Sent: Friday, April 28, 2006 6:46 PM To: Weber Sites LTD; php-general@lists.php.net Subject: Re: [PHP] RegExp for preg_split() At 6:16 PM +0200 4/28/06, Weber Sites LTD wrote: >Hi > >I'm looking for the RegExp that will split a search string into search >keywords. >while taking " " into account. > >From what I managed to find I can get all of the words into an array >but I would like all of the words inside " " to be in the same array >cell. > >NE1? > >thanks > >berber berber: Not knowing exactly what you want, this will sort out the "phrase strings". $string = 'Medaillons, Listels, "custom stuff", "more things", entryway, accents, showplace'; echo("$string "); preg_match_all ('/".*?"/', $string, $matchs); foreach($matchs[0] as $matchs) { echo("$matchs "); } HTH's tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp for preg_split()
At 6:16 PM +0200 4/28/06, Weber Sites LTD wrote: Hi I'm looking for the RegExp that will split a search string into search keywords. while taking " " into account. From what I managed to find I can get all of the words into an array but I would like all of the words inside " " to be in the same array cell. NE1? thanks berber berber: Not knowing exactly what you want, this will sort out the "phrase strings". $string = 'Medaillons, Listels, "custom stuff", "more things", entryway, accents, showplace'; echo("$string "); preg_match_all ('/".*?"/', $string, $matchs); foreach($matchs[0] as $matchs) { echo("$matchs "); } HTH's tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegExp for preg_split()
At 6:16 PM +0200 4/28/06, Weber Sites LTD wrote: Hi I'm looking for the RegExp that will split a search string into search keywords. while taking " " into account. From what I managed to find I can get all of the words into an array but I would like all of the words inside " " to be in the same array cell. NE1? thanks berber berber: In other words, you want phrases as well as keywords, is that correct? What's the string look like? tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RegExp for preg_split()
Hi I'm looking for the RegExp that will split a search string into search keywords. while taking " " into account. >From what I managed to find I can get all of the words into an array but I would like all of the words inside " " to be in the same array cell. NE1? thanks berber
Re: [PHP] Regexp matching in SQL
Brian Anderson wrote: "IN ( exp1, exp2)" didn't seem to work for me. I've seen that used before for including a subquery, but somehow it didn't like the comma separated list. I think this below is doing it for me. $separated = implode("|", (explode(" ", (AddSlashes($_REQUEST['terms']); if($_REQUEST['c'] == "and"){ $conditional = 'AND'; }else{ $conditional = 'OR'; } $delim = " WHERE Keyword REGEXP '$separated' $conditional ItemDescription REGEXP '$separated'"; I'm still curious about the IN() keyword and how it works. in() is good for id's: select * from table where categoryid in (1,2,3,4,5); it's basically expanded to an or: select * from table where categoryid=1 or categoryid=2 or categoryid=3 or categoryid=4 or categoryid=5; [EMAIL PROTECTED] wrote: [snip] I am trying to simplify an SQL query that is pretty much like below: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR keyword RLIKE '$expression2' "; The different terms '$expression1' and '$expression1' come from an array. Is there any way to within one regular expression to say either term1 or term 2? Something like this where the OR condition would be basically built into the regular expression: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the $expression would have to signify either a or b. Does that make sense? [/snip] Kinda'. If you asked on a SQL board they would say do this; SELECT * FROM table WHERE keyword IN ($expression1, $expression2) IN is the shorthand for multiple OR conditions. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp matching in SQL
"IN ( exp1, exp2)" didn't seem to work for me. I've seen that used before for including a subquery, but somehow it didn't like the comma separated list. I think this below is doing it for me. $separated = implode("|", (explode(" ", (AddSlashes($_REQUEST['terms']); if($_REQUEST['c'] == "and"){ $conditional = 'AND'; }else{ $conditional = 'OR'; } $delim = " WHERE Keyword REGEXP '$separated' $conditional ItemDescription REGEXP '$separated'"; I'm still curious about the IN() keyword and how it works. -Brian [EMAIL PROTECTED] wrote: [snip] I am trying to simplify an SQL query that is pretty much like below: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR keyword RLIKE '$expression2' "; The different terms '$expression1' and '$expression1' come from an array. Is there any way to within one regular expression to say either term1 or term 2? Something like this where the OR condition would be basically built into the regular expression: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the $expression would have to signify either a or b. Does that make sense? [/snip] Kinda'. If you asked on a SQL board they would say do this; SELECT * FROM table WHERE keyword IN ($expression1, $expression2) IN is the shorthand for multiple OR conditions. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regexp matching in SQL
[snip] I am trying to simplify an SQL query that is pretty much like below: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR keyword RLIKE '$expression2' "; The different terms '$expression1' and '$expression1' come from an array. Is there any way to within one regular expression to say either term1 or term 2? Something like this where the OR condition would be basically built into the regular expression: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the $expression would have to signify either a or b. Does that make sense? [/snip] Kinda'. If you asked on a SQL board they would say do this; SELECT * FROM table WHERE keyword IN ($expression1, $expression2) IN is the shorthand for multiple OR conditions. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regexp matching in SQL
I am trying to simplify an SQL query that is pretty much like below: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR keyword RLIKE '$expression2' "; The different terms '$expression1' and '$expression1' come from an array. Is there any way to within one regular expression to say either term1 or term 2? Something like this where the OR condition would be basically built into the regular expression: $sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the $expression would have to signify either a or b. Does that make sense? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp trouble
Andy Pieters wrote: > > Err.. why NOT use character classes? What is easier [0-9] or \d or maybe > [a-zA-Z] or [\w], ... ? > Well, first of all the square brackets in [\w] aren't needed, \w already means 'any "word" character'. Secondly, [a-zA-Z] is not the same as \w: " A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place (see "Locale support" above). For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w. " [http://www.php.net/manual/en/reference.pcre.pattern.syntax.php] Anyway I'm not really a great RegExp expert, a good starting point for understanding regexp and PHP is, as usual, the manual: http://www.php.net/manual/en/reference.pcre.pattern.syntax.php Bye! -- tradeOver | http://www.tradeover.net ...ready to become the King of the World? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp trouble
Thanks all for your contributions. Seems like the missing link was the delimiter. On Thursday 24 November 2005 18:23, Frank Armitage wrote: > > And why do you use all those character > classes? > Err.. why NOT use character classes? What is easier [0-9] or \d or maybe [a-zA-Z] or [\w], ... ? With kind regards Andy -- Now listening to Top! Radio Live www.topradio.be/stream on amaroK Geek code: www.vlaamse-kern.com/geek Registered Linux User No 379093 If life was for sale, what would be its price? www.vlaamse-kern.com/sas/ for free php utilities -- pgposVVooZ7Uo.pgp Description: PGP signature
Re: [PHP] Regexp trouble
Andy Pieters wrote: Hi list I still fail to understand why regular expressions are causing me such a hard time. er, because they are hard? hey you failed! we have a club :-) I used and tested my regexp in kregexpeditor (comes with Quanta [kdewebdev]) but when I put it in the php script it fails. ereg('^([\w]{3,3})[\s]([\d]{2,2})[\s]([\d]{2,2})[:]([\d]{2,2})[:]([\d]{2,2})' I always use the preg_*() functions myself. and I always have to specify regexp delimiters ... $re = "#^([\w]{3,3})[\s]([\d]{2,2})[\s]([\d]{2,2})[:]([\d]{2,2})[:]([\d]{2,2})#"; $st = "Nov 22 06:51:36"; echo (preg_match($re, $st) ? "Yes":"No"),"\n"; I ran the above and it returned 'Yes' for me. Does not match my query string. Which is Nov 22 06:51:36 Any ideas why? I mean Line start, followed by 3 word chars, followed by a space, followed by 2 digits, followed by a space, followed by two digits, folowed by a colon followed by 2 digits and followed by a colon, should match that date? With kind regards Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp trouble
Andy Pieters wrote: > Hi list > > I still fail to understand why regular expressions are causing me such a hard > time. > > Hi! Why don't you use 'preg_match'? And why do you use all those character classes? This: $subject = 'Nov 22 06:51:36'; $pattern = '/^(\w{3})\s(\d{2})\s(\d{2}):(\d{2}):(\d{2})/'; if (preg_match($pattern, $subject, $matches)) { print_r($matches); } nicely prints: Array ( [0] => Nov 22 06:51:36 [1] => Nov [2] => 22 [3] => 06 [4] => 51 [5] => 36 ) Bye Frank -- tradeOver | http://www.tradeover.net ...ready to become the King of the World? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp trouble
Andy, Try preg_match instead of ereg. Cheers, David Grant Andy Pieters wrote: > Hi list > > I still fail to understand why regular expressions are causing me such a hard > time. > > I used and tested my regexp in kregexpeditor (comes with Quanta [kdewebdev]) > but when I put it in the php script it fails. > > ereg('^([\w]{3,3})[\s]([\d]{2,2})[\s]([\d]{2,2})[:]([\d]{2,2})[:]([\d]{2,2})' > > Does not match my query string. > > Which is > > Nov 22 06:51:36 > > Any ideas why? I mean Line start, followed by 3 word chars, followed by a > space, followed by 2 digits, followed by a space, followed by two digits, > folowed by a colon followed by 2 digits and followed by a colon, should match > that date? > > With kind regards > > > Andy > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regexp trouble
Hi list I still fail to understand why regular expressions are causing me such a hard time. I used and tested my regexp in kregexpeditor (comes with Quanta [kdewebdev]) but when I put it in the php script it fails. ereg('^([\w]{3,3})[\s]([\d]{2,2})[\s]([\d]{2,2})[:]([\d]{2,2})[:]([\d]{2,2})' Does not match my query string. Which is Nov 22 06:51:36 Any ideas why? I mean Line start, followed by 3 word chars, followed by a space, followed by 2 digits, followed by a space, followed by two digits, folowed by a colon followed by 2 digits and followed by a colon, should match that date? With kind regards Andy -- Currently not listening to amaroK Geek code: www.vlaamse-kern.com/geek Registered Linux User No 379093 If life was for sale, what would be its price? www.vlaamse-kern.com/sas/ for free php utilities -- pgpB6BsWHneC5.pgp Description: PGP signature
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Owkay i fixed it :D. The regexp needed a /s (Pattern Modifier) also so that the "."(DOT) also does newlines :). Now it is fixed... Thank you very much Eli :) /me is happy. THE CODE: --- http://www.php.net/index.php> key=value "; echo 'Normal HTML:'; echo $html; echo ""; $improved_html = preg_replace('/\<(.*)\>/Ueis','"<".tag_rep("\1").">"',$html); echo 'Improved HTML:'; echo str_replace("\\'","'",$improved_html); echo ""; ?> --- "BlackDex" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thx... it works almost :P > > I Changed the code a bit so you can see the results quicker :). > > It doesn't change every attribute/value. I think this has to do something > with the opening and closing of a tag <>. > > --- > > "Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Sorry for the spam.. here it is: >> >> > function tag_rep($tag) >> { >>return >> preg_replace('/(?> } >> >> $html="> lang=NL style='font-size:12.0pt;font-family:\"Comic >> Sans MS\"'>> href=http://www.php.net/index.php> key=value "; >> >> $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); >> echo str_replace("\\'","'",$improved_html); >> ?> >> >> :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Owkay.. i fixed it :). Here is the final code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP RegExp and HTML tags attributes values etc...
"Jason Petersen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 10 Mar 2005 00:18:05 +0100, BlackDex <[EMAIL PROTECTED]> wrote: >> Hello ppl, >> >> I have a question about regex and html parsing. >> >> I have the following code: >> --- >> > style='font-size:12.0pt;font-family:"Comic Sans >> MS"'> > > I'm guessing that you're writing a function to parse "HTML" that users > upload via a web form? I would start with a look at this Perl script > to fix code generated by MS products: > > http://www.fourmilab.ch/webtools/demoroniser/ > --- Il go and check it out.. --- > Also, PHP's "libtidy" extension might be useful for you, although I > haven't used it personally. --- I have tryed it.. But it removes/changes to much even if i disable all the tidy settings. So thats not an option :(. --- > > http://us2.php.net/manual/en/ref.tidy.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP RegExp and HTML tags attributes values etc...
On Thu, 10 Mar 2005 00:18:05 +0100, BlackDex <[EMAIL PROTECTED]> wrote: > Hello ppl, > > I have a question about regex and html parsing. > > I have the following code: > --- > style='font-size:12.0pt;font-family:"Comic Sans MS"'> I'm guessing that you're writing a function to parse "HTML" that users upload via a web form? I would start with a look at this Perl script to fix code generated by MS products: http://www.fourmilab.ch/webtools/demoroniser/ Also, PHP's "libtidy" extension might be useful for you, although I haven't used it personally. http://us2.php.net/manual/en/ref.tidy.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Thx... it works almost :P I Changed the code a bit so you can see the results quicker :). It doesn't change every attribute/value. I think this has to do something with the opening and closing of a tag <>. My code: --- http://www.php.net/index.php> key=value "; echo 'Normal HTML:'; echo $html; echo ""; $improved_html = preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); echo 'Improved HTML:'; echo str_replace("\\'","'",$improved_html); echo ""; ?> --- "Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Sorry for the spam.. here it is: > > function tag_rep($tag) > { >return > preg_replace('/(? } > > $html=" lang=NL style='font-size:12.0pt;font-family:\"Comic Sans MS\"'> href=http://www.php.net/index.php> key=value "; > > $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); > echo str_replace("\\'","'",$improved_html); > ?> > > :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP RegExp and HTML tags attributes values etc...
Eli wrote: BlackDex wrote: Hello ppl, I have a question about regex and html parsing. I have the following code: --- style='font-size:12.0pt;font-family:"Comic Sans MS"'> you realise that that HTML ammounts the to the display of a SINGLE space!!! that what I call progress... 144+ bytes to display " ". I do hope M$ has hired a whole army of programmers to develop XML applications/generators/etc that are just as good as FrontPage ... er not :-) my solution to M$ BHTML (B for Bullshit) is strip_tags() -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Sorry for the spam.. here it is: function tag_rep($tag) { return preg_replace('/(? } $html="http://www.php.net/index.php> key=value "; $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); echo str_replace("\\'","'",$improved_html); ?> :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Yup.. that was a good point.. ;) Take a look at this example: function tag_rep($tag) { return reg_replace('/(? } $html="http://www.php.net/index.php> key=value "; $improved_html=preg_replace('/\<(.*)\>/Ue','"<".tag_rep("\1").">"',$html); echo str_replace("\'","'",$improved_html); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
"Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Eli wrote: >> >> Try: >> >> preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); >> Hmm.. that could be a >> start.. and don't ask me how it works... :P > > Well.. problem with that, is that if you got more than 1 un-escaped attribute > in a tag, the regex will fix only the first > un-escaped attribute. > > for example, if $html is: > style='font-size:12.0pt;font-family:"Comic Sans MS"'> > > In that case the id=par will remain as is... > Does anyone knows how to improve it? Just looking at the online mailinglist.. checkout this link, mabye it can help.. http://marc.theaimsgroup.com/?l=php-general&m=97975368123802&w=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
"Eli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Eli wrote: >> >> Try: >> >> preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); >> Hmm.. that could be a >> start.. and don't ask me how it works... :P > > Well.. problem with that, is that if you got more than 1 un-escaped attribute > in a tag, the regex will fix only the first > un-escaped attribute. > > for example, if $html is: > style='font-size:12.0pt;font-family:"Comic Sans MS"'> > > In that case the id=par will remain as is... > Does anyone knows how to improve it? First of all thx :). Just an idea... (Becouse im not that good at it). Is it possible to create a while loop for the whole <> part? Simply sad... while <.*?> do { parse the contents of that tag in someway and change it? } Becouse i think it is imposible with RegEx alone to make it so that it can handle every attribute within a tag. Ltrz BlackDex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
Eli wrote: Try: preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); Hmm.. that could be a start.. and don't ask me how it works... :P Well.. problem with that, is that if you got more than 1 un-escaped attribute in a tag, the regex will fix only the first un-escaped attribute. for example, if $html is: style='font-size:12.0pt;font-family:"Comic Sans MS"'> In that case the id=par will remain as is... Does anyone knows how to improve it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP RegExp and HTML tags attributes values etc...
BlackDex wrote: Hello ppl, I have a question about regex and html parsing. I have the following code: --- --- It laks some quotemarks. I want to change it to: --- --- So it will have " around the attribute values... But i can't figure out how to do that :(. Can anyone help me with this?? Thx in advance. Kind Regards, BlackDex Try: preg_replace('/(?<=\<)([^>]*)(\w+)=(?\s]+)(?=\s|\>)([^<]*)(?=\>)/U','\1\2="\3"\4',$html); Hmm.. that could be a start.. and don't ask me how it works... :P -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP RegExp and HTML tags attributes values etc...
Hello ppl, I have a question about regex and html parsing. I have the following code: --- --- It laks some quotemarks. I want to change it to: --- --- So it will have " around the attribute values... But i can't figure out how to do that :(. Can anyone help me with this?? Thx in advance. Kind Regards, BlackDex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp stopped working on my site
The expression that I found won't work anymore is an own pseudo-lang markup that renders into html-lists. Expression for grabbing a list, Example: [lista] some text [/lista] @\[\s*(lista)\s*(sq|o|\*|#|a|i)?\s*\]([^\x00]*?)\[/[EMAIL PROTECTED] $3 is then treated separated into html list-items . List-items are created by a pseudotag [punkt] or linebreaks. Its one way, you can't mix them both here. // Explode the string into an array $hits = preg_split('#(\[\s*punkt\s*\][^\x00]*?\[/\s*\punkt\s*\])#', $matches[3], -1, PREG_SPLIT_DELIM_CAPTURE); $textarray=array(); foreach($hits as $index=>$element){ if( ($index%2)==0){ // strings $element = preg_split('/\s*\r+ \s*/', trim($element), -1, PREG_SPLIT_NO_EMTPY); foreach($element as $val){ // Replace innerstyles if(strlen(trim ($val))>0){ // Replace nestled lists //$val=$this- >search_and_replace($val, $this->_reg_search['lista'] ); $val=$this- >_check_content($val , $matches[1] ); // Add list element array_push ($textarray, ''.$val.''); } } }else{ // [punkt] $element=preg_replace('# \[\s*punkt\s*\]([^\x00]*?)\[/\s*\punkt\s*\]#', '$1',$element); // replace linebreaks $element = preg_replace('/\r/', '', $element); // Replace innerstyles // Replace nestled lists //$val=$this->search_and_replace ($val, $this->_reg_search['lista'] ); $element=$this->_check_content ($element , $matches[1] ); // Add list element array_push($textarray, ''.$element.''); } } > Kristian Hellquist wrote: > > Hi! > > > > I had a script for parsing text into html, similar to phpBB. Everything > > has been working fine until now. Some of my 'pseudotags' like [b] are > > still recognized (parsed into ) but some more advanced pattern > > matching is not. I haven't changed the code, but the php-version on the > > server has changed from "default" on debian-woody to php-4.3.10. I > > haven't made the upgrade myself. > > > > The users of the site reported the bug to me this week, but the users > > aren't active so I don't really know when then bug was created. Because > > I know it has worked before. > > > > Does any of you have a clue or experience of this? Or has my code been > > mysterious altered on the server? > > An example of the expressions? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp stopped working on my site
Kristian Hellquist wrote: Hi! I had a script for parsing text into html, similar to phpBB. Everything has been working fine until now. Some of my 'pseudotags' like [b] are still recognized (parsed into ) but some more advanced pattern matching is not. I haven't changed the code, but the php-version on the server has changed from "default" on debian-woody to php-4.3.10. I haven't made the upgrade myself. The users of the site reported the bug to me this week, but the users aren't active so I don't really know when then bug was created. Because I know it has worked before. Does any of you have a clue or experience of this? Or has my code been mysterious altered on the server? An example of the expressions? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regexp stopped working on my site
Hi! I had a script for parsing text into html, similar to phpBB. Everything has been working fine until now. Some of my 'pseudotags' like [b] are still recognized (parsed into ) but some more advanced pattern matching is not. I haven't changed the code, but the php-version on the server has changed from "default" on debian-woody to php-4.3.10. I haven't made the upgrade myself. The users of the site reported the bug to me this week, but the users aren't active so I don't really know when then bug was created. Because I know it has worked before. Does any of you have a clue or experience of this? Or has my code been mysterious altered on the server? Thanks! Kristian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp help second
On Thu, 06 Jan 2005 13:50:58 +0100, UroÅ Gruber <[EMAIL PROTECTED]> wrote: > > 1) this is some domain.com test > 2) domain.com > > I can make this work either for first example of fo second, but not for > both. What I want is replace of domain.com to get > > this is dome domain.com domain com test so replace should be > \1 \2 \3 > > so for second example I did /((.+)\.{1}(.+))/ > > How can I extend this to work in both. > Can you explain in a little more detail what you're trying to replace domain.com with? I'm having trouble understanding your intentions. A regular expression like: /([\w-]+)\.([\w-]+)/ should be able to grab strings like domain.com in any type of string (I'm using the preg_replace function). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regexp help second
You could maybe cheat and add an X at the beginning and end of the string before your Regex, then you will have: X\1 \2 \3X and you can strip off the initial X from \1 and the trailing X from \3 There's probably some fancy Regexp way to do it though. Uroš Gruber wrote: > Hi! > > Last help about regexp solve my problem, but I have another one. > > I've made some regexp but it does not work always > > Let say I have some strings > > 1) this is some domain.com test > 2) domain.com > > I can make this work either for first example of fo second, but not for > both. What I want is replace of domain.com to get > > this is dome domain.com domain com test so replace should be > \1 \2 \3 > > so for second example I did /((.+)\.{1}(.+))/ > > How can I extend this to work in both. > > regards > > Uros > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php