[PHP] Re: Regex help
Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) /purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] prehaps -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/ documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) / purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Thanks for looking though! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
Jason Pruim wrote: On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) /purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Thanks for looking though! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] here's a typical rule; probably best to modify what works and go from there :) RewriteRule ^directory/(.*)$ /newdirectory/$1 [L] the other alternative is to let php handle it.. this is basicaly if request isn't a file or a directory route to a php handler [my prefered way]: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /notfound_handler.php [L] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
Jason Pruim wrote: On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/ documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) / purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Maybe this: RewriteCond %{REQUEST_URI} !^/p\.php RewriteRule ^/(.+)$ /p.php?purl=$1 /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
On Sep 9, 2008, at 5:02 PM, Nathan Rixham wrote: Jason Pruim wrote: On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/ documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) / purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Thanks for looking though! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] here's a typical rule; probably best to modify what works and go from there :) RewriteRule ^directory/(.*)$ /newdirectory/$1 [L] the other alternative is to let php handle it.. this is basicaly if request isn't a file or a directory route to a php handler [my prefered way]: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /notfound_handler.php [L] Interesting idea... I hadn't thought about that... Then I could just use a regex in php and grab everything after the domain name and pass it to my database to search and find the appropriate info to pull out... I'll have to do some searching :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
Jason Pruim schreef: On Sep 9, 2008, at 5:02 PM, Nathan Rixham wrote: Jason Pruim wrote: On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) /purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Thanks for looking though! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] here's a typical rule; probably best to modify what works and go from there :) RewriteRule ^directory/(.*)$ /newdirectory/$1 [L] the other alternative is to let php handle it.. this is basicaly if request isn't a file or a directory route to a php handler [my prefered way]: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /notfound_handler.php [L] RewriteRule . /notfound_handler.php [L,QSA] the QSA tells apache to to automatically append any query string, saves the hassle of having to deal with it in the regexp (assuming you might need it) also beware that external redirects will cause POSTs to become GETs so that the script/code in question never recieves the POST. Interesting idea... I hadn't thought about that... Then I could just use a regex in php and grab everything after the domain name and pass it to my database to search and find the appropriate info to pull out... your probably wanting the info in $_SERVER['REQUEST_URI'] ... which is the complete uri before it was rewritten. also check this func out, will probably spare you the regexp completely: http://php.net/manual/en/function.parse-url.php I'll have to do some searching :) always ;-) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
On Sep 9, 2008, at 12:18 PM, Jochem Maas wrote: Jason Pruim schreef: On Sep 9, 2008, at 5:02 PM, Nathan Rixham wrote: Jason Pruim wrote: On Sep 9, 2008, at 4:38 PM, Nathan Rixham wrote: Jason Pruim wrote: Hey everyone, Not completely specific to php but I know you guys know regex's better then I do! :) I am attempting to match purl.schreurprinting.com/jasonpruim112 to purl.schreurprinting.com/p.php?purl=jasonpruim112 Here are my current matching patterns: RewriteRule /(.*) /volumes/raider/webserver/ documents/dev/schreurprinting.com/p.php?purl=$ # RewriteRule /(*.) /purl.schreurprinting.com/$1 # RewriteRule /(mail.php?purl=*) / purl.schreurprinting.com/mail.php?purl=$1 Yes I am doing this for apache's mod_rewrite, but my question is much more specific to regex's at this point :) Any ideas where I am going wrong? it seems like it should be fairly simple to do, but I don't know regex's at all :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] RewriteRule ^jasonpruim112$ /p.php?purl=jasonpruim112 [L] Just tried it, and it pops up with a 404... I'll keep looking. One other thing that I should probably add is the fact that the ^jasonpruim112$ could have hundreds of counterparts ^bobsmith112$ ^jerrybob112$ etc... etc... Thanks for looking though! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] here's a typical rule; probably best to modify what works and go from there :) RewriteRule ^directory/(.*)$ /newdirectory/$1 [L] the other alternative is to let php handle it.. this is basicaly if request isn't a file or a directory route to a php handler [my prefered way]: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /notfound_handler.php [L] RewriteRule . /notfound_handler.php [L,QSA] the QSA tells apache to to automatically append any query string, saves the hassle of having to deal with it in the regexp (assuming you might need it) also beware that external redirects will cause POSTs to become GETs so that the script/code in question never recieves the POST. Interesting... that may explain a problem I am having with some other local links in that directory... Interesting idea... I hadn't thought about that... Then I could just use a regex in php and grab everything after the domain name and pass it to my database to search and find the appropriate info to pull out... your probably wanting the info in $_SERVER['REQUEST_URI'] ... which is the complete uri before it was rewritten. That's actually what I started using, then I just explode that to get my query string to use in the database lookup. also check this func out, will probably spare you the regexp completely: http://php.net/manual/en/function.parse-url.php Ohhh... That sounds promising... I'll have to take a look at it later. I'll have to do some searching :) always ;-) The problem with the internet is there is so much out there... Trying to weed the crap from the food can be a long digestive process which ends up with MORE crap coming out... This list... It's like pepto bismo for my programming :P -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex help
Jason Pruim schreef: On Sep 9, 2008, at 12:18 PM, Jochem Maas wrote: ... I'll have to do some searching :) always ;-) The problem with the internet is there is so much out there... Trying to weed the crap from the food can be a long digestive process which ends up with MORE crap coming out... This list... It's like pepto bismo for my programming :P and there is us trying so hard to give everyone stomach ulcers :-) must try harder. -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 11287 James St Holland, MI 49424 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: REGEX Help Please
I am trying to implement a regular expression so that I have a number between 0.00 and 1.00. the following works except I can go up to 1.99 $regexp = /^[0-1]{1}.[0-9]{2}/; You could always do this, unless you are set on using a regular expression: if($num=0 $num=1.01){ echo number_format($num,2); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regex help
RaTT wrote: Hi Guys, I am currently creating a once off text parser for a rather large document that i need to strip out bits of information on certain lines. The line looks something like : Adress line here, postcode, country Tel: +27 112233665 Fax: 221145221 Website: http://www.urlhere.com E-Mail: [EMAIL PROTECTED] TAGINCAPS: CAPS RESPONSE Tag2: blah I need to retreive the text after each marker i.e Tel: Fax: E-Email: TAGINCAPS: ... I have the following regex /Tel:\s*(.[^A-z:]+)/ and /Fax:\s*(.[^A-z:]+)/ all these work as expected and stop just before the next Tag. However I run into hassels around the TAGINCAPS as the response after it is all in caps and i cant get the Regex to stop just before the next tag: which may be either all caps or lowercase. I cant seem to find the regex that will retreive all chartures just before a word with a : regalrdless of case. I have played around with the regex coach but still seem to be comming up short so i thought i would see if anybody can see anything i might have missed. any help most appreciated. Regards Jarratt Add and i for case insensitive for all except the numbers type e.g., /TAGINCAPS:\s*(.[A-z:]+)/i -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regex help
On Fri, 28 Jan 2005 14:59:29 -0700, [EMAIL PROTECTED] wrote: OK, this is off-topic like every other regex help post, but I know some of you enjoy these puzzles :) I need a validation regex that will pass a string. The string can be no longer than some maximum length, and it can contain any characters except two consecutive ampersands () anywhere in the string. I'm stumped - ideas? TIA Kirk if(preg_match(/^([^]|(?!)){1,42}$/,$string)) { This one will work I think. Returns false if it finds two consecutive or exceeds 42 chars. -- Stian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex help and file question
Php Gen [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I am just starting out with regex (and classes) so am not sure how to do this... I am seeing if a HTML file exists, if yes, I am using file_get_contents to get the entire HTML file into a string. In the HTML file I already have this: !-- Start header -- html body whatever you want comes here !-- End header -- How do I use a regex to span these multiple lines and simply cut everything (including the start..end part)from !-- Start header -- to !-- End header -- Second question: I am using file_get_contents, is it better to use this than file() or fread() ? Thanks, Mag Hi, I can't answer your regexp question but some thoughts on file() etc.: - file() returns the contents line by line as an array, so this makes only sense if you need the contents in this form, e.g. for looping through each line and applying a function or whatever - fread() requires a file handle that you have to create with fopen(), so file_get_contents() is kind of a shortcut for fopen()/fread() Hope this helps. Regards, Torsten Roehr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: regex help and file question
Hi, I can't answer your regexp question but some thoughts on file() etc.: - file() returns the contents line by line as an array, so this makes only sense if you need the contents in this form, e.g. for looping through each line and applying a function or whatever - fread() requires a file handle that you have to create with fopen(), so file_get_contents() is kind of a shortcut for fopen()/fread() Hey, Thanks for replying and the answer to my second Q, sounds like file_get_contents() is good for me now. I think i found a solution for the regex too, just have to modify some parts. Cheers, Mag = -- - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) __ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: regex help needed -- Solved! Thanks!
Kathleen Ballard a écrit : Thanks! Works like a charm! I am the very lowest of newbies when it comes to regex and working through your solutions has been very educational. I have one question about something I couldn't figure out: #h[1-9](.*)/h[1-9]#Uie `h([1-6]).*?/h\1)`sie What is the purpose of the back-ticks and the '#'? PCRE patterns has to be enclosed, you can use all the non alpha numerics characters to do that. Personnaly, I prefer back ticks because I don't have to escape it often inside my patterns. For my example, you can also remove the ``s pattern modifier, It makes the dot ( . ) accept any New line characters, and I had not see that you removed them before. What are 'Uie' and 'sie'? there are patterns modifiers, you can find a complete list and descriptions here : http://www.php.net/manual/en/pcre.pattern.modifiers.php Thanks again! Kathleen -Original Message- From: Fabrice Lezoray [mailto:[EMAIL PROTECTED] Sent: Sunday, August 01, 2004 2:52 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: regex help needed hi M. Sokolewicz a écrit : You could try something like: $return = preg_replace('#h[1-9](.*)/h[1-9]#Uie', 'str_replace(br /, , $1)'); - Tul Kathleen Ballard wrote: Sorry, Here is the code I am using to match the h* tags: h([1-9]){1}.*/h([1-9]){1} I think this mask is better : `h([1-6]).*?/h\1)`sie I have removed all the NL and CR chars from the string I am matching to make things easier. Also, I have run tidy on the code so the tags are all uniform. The above string seems to match the tag well now, but I still need to remove the br tags from the tag contents (.*). To remove the br / tags, you need to call preg_replace_callback() : ?php $str = 'h1hi br / ../h1 bla bla h5 br / ../h5 ...br /'; function cbk_br($match) { return 'h' . $match[1] . '' . str_replace('br /', '', $match[2]) . '/h' . $match[1] . ''; } $return = preg_replace_callback('`h([1-6])(.*?)/h\1`si', 'cbk_br', $str); echo $return; ? The strings I will be matching are html formatted text. Sample h* tags with content are below: h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary/h4 h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary br / Wins New Jersey/h4 h4Ex-Secretary Reich Loses Mass. Primary/h4 Again, any help is appreciated. Kathleen Sorry for my bad english .. -- Fabrice Lezoray http://classes.scriptsphp.fr - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex help needed
You could try something like: $return = preg_replace('#h[1-9](.*)/h[1-9]#Uie', 'str_replace(br /, , $1)'); - Tul Kathleen Ballard wrote: Sorry, Here is the code I am using to match the h* tags: h([1-9]){1}.*/h([1-9]){1} I have removed all the NL and CR chars from the string I am matching to make things easier. Also, I have run tidy on the code so the tags are all uniform. The above string seems to match the tag well now, but I still need to remove the br tags from the tag contents (.*). The strings I will be matching are html formatted text. Sample h* tags with content are below: h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary/h4 h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary br / Wins New Jersey/h4 h4Ex-Secretary Reich Loses Mass. Primary/h4 Again, any help is appreciated. Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex help needed
hi M. Sokolewicz a écrit : You could try something like: $return = preg_replace('#h[1-9](.*)/h[1-9]#Uie', 'str_replace(br /, , $1)'); - Tul Kathleen Ballard wrote: Sorry, Here is the code I am using to match the h* tags: h([1-9]){1}.*/h([1-9]){1} I think this mask is better : `h([1-6]).*?/h\1)`sie I have removed all the NL and CR chars from the string I am matching to make things easier. Also, I have run tidy on the code so the tags are all uniform. The above string seems to match the tag well now, but I still need to remove the br tags from the tag contents (.*). To remove the br / tags, you need to call preg_replace_callback() : ?php $str = 'h1hi br / ../h1 bla bla h5 br / ../h5 ...br /'; function cbk_br($match) { return 'h' . $match[1] . '' . str_replace('br /', '', $match[2]) . '/h' . $match[1] . ''; } $return = preg_replace_callback('`h([1-6])(.*?)/h\1`si', 'cbk_br', $str); echo $return; ? The strings I will be matching are html formatted text. Sample h* tags with content are below: h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary/h4 h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary br / Wins New Jersey/h4 h4Ex-Secretary Reich Loses Mass. Primary/h4 Again, any help is appreciated. Kathleen -- Fabrice Lezoray http://classes.scriptsphp.fr - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: regex help needed -- Solved! Thanks!
Thanks! Works like a charm! I am the very lowest of newbies when it comes to regex and working through your solutions has been very educational. I have one question about something I couldn't figure out: #h[1-9](.*)/h[1-9]#Uie `h([1-6]).*?/h\1)`sie What is the purpose of the back-ticks and the '#'? What are 'Uie' and 'sie'? Thanks again! Kathleen -Original Message- From: Fabrice Lezoray [mailto:[EMAIL PROTECTED] Sent: Sunday, August 01, 2004 2:52 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: regex help needed hi M. Sokolewicz a écrit : You could try something like: $return = preg_replace('#h[1-9](.*)/h[1-9]#Uie', 'str_replace(br /, , $1)'); - Tul Kathleen Ballard wrote: Sorry, Here is the code I am using to match the h* tags: h([1-9]){1}.*/h([1-9]){1} I think this mask is better : `h([1-6]).*?/h\1)`sie I have removed all the NL and CR chars from the string I am matching to make things easier. Also, I have run tidy on the code so the tags are all uniform. The above string seems to match the tag well now, but I still need to remove the br tags from the tag contents (.*). To remove the br / tags, you need to call preg_replace_callback() : ?php $str = 'h1hi br / ../h1 bla bla h5 br / ../h5 ...br /'; function cbk_br($match) { return 'h' . $match[1] . '' . str_replace('br /', '', $match[2]) . '/h' . $match[1] . ''; } $return = preg_replace_callback('`h([1-6])(.*?)/h\1`si', 'cbk_br', $str); echo $return; ? The strings I will be matching are html formatted text. Sample h* tags with content are below: h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary/h4 h4Ex-Secretary Mickey Mouse br /Loses Mass. Primary br / Wins New Jersey/h4 h4Ex-Secretary Reich Loses Mass. Primary/h4 Again, any help is appreciated. Kathleen -- Fabrice Lezoray http://classes.scriptsphp.fr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex Help
Hi Ben, Your code works but If i remove the delimter [] which I gave so that you could capture the data which needs to be picked it doesnt work?. Any help? Karthikeyan B - Original Message - From: Ben Ramsey [EMAIL PROTECTED] To: [EMAIL PROTECTED]; Karthikeyan [EMAIL PROTECTED] Sent: Monday, January 26, 2004 11:56 PM Subject: [PHP] Re: Regex Help Check the PHP manual for preg_match() (http://us3.php.net/manual/en/function.preg-match.php). I did play around with it a little bit, and I think I've got a starting point for you to work with. Try out this code and then play around with it to get the results you need. $matches[2][0] will hold the full line for Mayberry Mob. You could then just use the substr() function to pull the data from that line. The code is, as follows: $subject = = NF [1/21/04] E Race 11 Grade B [5-16] Going F U Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm Inside Dream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc Mdtk Pounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show Inside Oneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly Inside Krazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk Mayberry Mob 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent Ins Jw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor Mdtrk Rooftop Comet56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk ; $pattern = /\[(\d+\/\d+\/\d+|\d+\-\d+)\]|(Mayberry Mob.*)/; if (preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER)) { print_r($matches); } else { echo no match.; } Hope that helps! Karthikeyan wrote: Sorry last time I forgot to put subject on my mail. So here I am putting appropriate subject and sending it. Hi All, Just wondering if somebody can help me with this small regex search. The information I wanted to capture is the one in the Square Bracket. i.e Date : 1/21/04, Race Type: 5-16, Dog Position: 6(Mayberry Mob) = NF [1/21/04] E Race 11 Grade B [5-16] Going F U Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm Inside Dream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc Mdtk Pounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show Inside Oneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly Inside Krazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk [Mayberry Mob] 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent Ins Jw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor Mdtrk Rooftop Comet56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk Looking forward to hear some response. Have a great day. Karthikeyan B -- 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] Re: Regex Help
Why do you need to remove the delimeters? If you remove them, then it makes it quite difficult to get the data you need. If you want to display the date and race type without the square brackets around them, then use $matches[0][1] and $matches[1][1] instead of $matches[0][0] or $matches[1][0]. Karthikeyan.Balasubramanian wrote: Hi Ben, Your code works but If i remove the delimter [] which I gave so that you could capture the data which needs to be picked it doesnt work?. Any help? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regex Help
Check the PHP manual for preg_match() (http://us3.php.net/manual/en/function.preg-match.php). I did play around with it a little bit, and I think I've got a starting point for you to work with. Try out this code and then play around with it to get the results you need. $matches[2][0] will hold the full line for Mayberry Mob. You could then just use the substr() function to pull the data from that line. The code is, as follows: $subject = = NF [1/21/04] E Race 11 Grade B [5-16] Going F U Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm Inside Dream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc Mdtk Pounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show Inside Oneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly Inside Krazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk Mayberry Mob 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent Ins Jw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor Mdtrk Rooftop Comet56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk ; $pattern = /\[(\d+\/\d+\/\d+|\d+\-\d+)\]|(Mayberry Mob.*)/; if (preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER)) { print_r($matches); } else { echo no match.; } Hope that helps! Karthikeyan wrote: Sorry last time I forgot to put subject on my mail. So here I am putting appropriate subject and sending it. Hi All, Just wondering if somebody can help me with this small regex search. The information I wanted to capture is the one in the Square Bracket. i.e Date : 1/21/04, Race Type: 5-16, Dog Position: 6(Mayberry Mob) = NF [1/21/04] E Race 11 Grade B [5-16] Going F U Too Tipsy 60½ 2 1 1 1 1 1 1 ½ 30.46 4.40 Held Firm Inside Dream Away 62 8 2 3 2 3 2 ½ 30.51 17.90 Up For Plc Mdtk Pounce N Bounce 70 5 4 2 1 2 3 2 30.58 4.50 Held Show Inside Oneco Conor 67½ 7 8 4 5 4 4 2 30.60 6.90 Evenly Inside Krazy Kirk 70 4 3 6 7 5 5 5 30.79 * 1.90 Varied Little Mdtrk [Mayberry Mob] 73½ 1 6 5 6 6 6 10 31.15 5.30 Never Prominent Ins Jw Alley's Wish 60 3 7 8 9 7 7 10 31.17 6.50 No Factor Mdtrk Rooftop Comet56 6 5 7 8 8 8 19 31.79 21.80 Never In It Mdtk Looking forward to hear some response. Have a great day. Karthikeyan B -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regex help please
Try this: $pattern = '#function (\w+)\(((?:\$\w+(?:,\s*\$\w+)*?)|\s*)\)\s*\{[.\s]*((?:return\s+[^;]*\s*;)|)[ .\s]*#m'; Notice that \w means: A word character is any letter or digit or the underscore character, that is, any character which can be part of a Perl word. Though, any regexp for this task can be easily fooled; i.e: there's no regexp for all cases; PHP's language cannot be described properly using just a regular expression. Manu. Shawn McKenzie [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have tried numerous variations, but my regex skills suck! I would appreciate anyone who can give me a pattern to use in preg_match_all() to match the following (I have the first part up to ANYTHING working): '|function ([\w\d\_]+)\((.*)\)ANYTHINGreturn (ANYTHING);|' So parsing a PHP file I hope to have 3 backreferences that return the function name, function args and return value (if present) of all functions. Thanks! -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: RegEx -- help
On Fri, 10 Oct 2003 14:01:00 -0400 (EDT), Lists [EMAIL PROTECTED] wrote: I do not know if this is the right list, but if someone could help me with the following Sure, I'll be glad to help. I need a function that does this: I'm not sure if you want me to write the code that does this for you, but I know that I wont. I'm just going to give you the tools that are commonly used for the tasks your asking for. function phone($num) { take num and remove anything that is not a number ex: () - / http://php.net/preg_replace If there is not 1 at the start, add a one to the start of the number. http://php.net/substr make sure that the number is 10 digits (if not return -1) http://php.net/strlen } Thank you for your help, In the future, please at least try and attempt to write the code, most people here arnt here to write code for everyone, but to solve problems people are having with their own code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: RegEx -- help
On Fri, 2003-10-10 at 16:18, Curt Zirzow wrote: On Fri, 10 Oct 2003 14:01:00 -0400 (EDT), Lists [EMAIL PROTECTED] wrote: I do not know if this is the right list, but if someone could help me with the following Sure, I'll be glad to help. I need a function that does this: I'm not sure if you want me to write the code that does this for you, but I know that I wont. I'm just going to give you the tools that are commonly used for the tasks your asking for. function phone($num) { take num and remove anything that is not a number ex: () - / http://php.net/preg_replace If there is not 1 at the start, add a one to the start of the number. http://php.net/substr make sure that the number is 10 digits (if not return -1) http://php.net/strlen } Thank you for your help, In the future, please at least try and attempt to write the code, most people here arnt here to write code for everyone, but to solve problems people are having with their own code. Incidentally the procedure for correcting the number is flawed. If you (original poster) have a 9 digit number with an area code beginning with a 1 then the required additional 1 will never be prepended. Really what you want is if the sequence of numbers is 9 digits long then precede with a 1. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex help?
hi john, try a regex like this: '/td[^]*(.*)/td/i' ciao SVEN John Herren wrote: Can't seem to get this to work... trying to yank stuff xxx from TD class=a8b noWrap align=middle width=17 bgColor=#ccxxx/TD and stuff yyy from TD class=a8b noWrap width=100nbsp;yyy/TD preg_match(|nbsp;(.*)/TD$|i, $l, $regs); works for the second example, even though it isn't the correct way, but nothing works for for me for the first example. Any help is appreciated! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regex help needed
First, the prob you got : WARNING comes from the following error: (\s+face=\Verdana, Arial, Helvetica, sans-serif\|) After the | (OR) sign, you must define another case, example: echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\(\s+face=\Verdana, Arial, Helvetica, sans-serif\|\s)\s*purchasing power parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1 face=Verdana, Arial, Helvetica, sans-seriftdfont size=2Purchasing power parity'); Secondly, it's right that the \s expression is not recognised in purchasing\s+power\s+parity , a little strange, but you can use two different ways instead of '\s': - [[:space:]] - [ ] The brackets allows you to define a sequence of characters patterns (in the second case above, the space character). It will give: echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\\s*purchasing[[:space:]]+power[[:space:]]+parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1tdfont size=2Purchasing power parity'); Just a little help, you can find on the page http://www.php.net/manual/en/ref.regex.php that could be useful for you: ^ Start of line $ End of line n? Zero or only one single occurrence of character 'n' n* Zero or more occurrences of character 'n' n+ At least one or more occurrences of character 'n' n{2} Exactly two occurrences of 'n' n{2,} At least 2 or more occurrences of 'n' n{2,4} From 2 to 4 occurrences of 'n' . Any single character () Parenthesis to group expressions (.*) Zero or more occurrences of any single character, ie, anything! (n|a) Either 'n' or 'a' [1-6] Any single digit in the range between 1 and 6 [c-h] Any single lower case letter in the range between c and h [D-M] Any single upper case letter in the range between D and M [^a-z] Any single character EXCEPT any lower case letter between a and z. Pitfall: the ^ symbol only acts as an EXCEPT rule if it is the very first character inside a range, and it denies the entire range including the ^ symbol itself if it appears again later in the range. Also remember that if it is the first character in the entire expression, it means start of line. In any other place, it is always treated as a regular ^ symbol. In other words, you cannot deny a word with ^undesired_word or a group with ^(undesired_phrase). Read more detailed regex documentation to find out what is necessary to achieve this. [_4^a-zA-Z] Any single character which can be the underscore or the number 4 or the ^ symbol or any letter, lower or upper case ?, +, * and the {} count parameters can be appended not only to a single character, but also to a group() or a range[]. therefore, ^.{2}[a-z]{1,2}_?[0-9]*([1-6]|[a-f])[^1-9]{2}a+$ would mean: ^.{2} = A line beginning with any two characters, [a-z]{1,2} = followed by either 1 or 2 lower case letters, _? = followed by an optional underscore, [0-9]* = followed by zero or more digits, ([1-6]|[a-f]) = followed by either a digit between 1 and 6 OR a lower case letter between a and f, [^1-9]{2} = followed by any two characters except digits between 1 and 9 (0 is possible), a+$ = followed by at least one or more occurrences of 'a' at the end of a line. Sid a écrit: Hello, Well I am doing by first reg ex operations and I am having problems which I just cannot figure out. For example I tried echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\\s*purchasing power parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1tdfont size=2Purchasing power parity'); and this worked perfectly, but when I chnaged that to echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\\s*purchasing\s+power\s+parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1tdfont size=2Purchasing power parity'); It does not detect the string. Srange. According to what I know, \s+ will detect a single space also. I tried chnaging the last 2 \s+ to \s* but this did not work also. Any ideas on this one? As I proceed I would like the expression to detect the optional face attribute also, so I tried echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\(\s+face=\Verdana, Arial, Helvetica, sans-serif\|)\s*purchasing power parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1 face=Verdana, Arial, Helvetica, sans-seriftdfont size=2Purchasing power parity'); ... and this gave me an error like Warning: eregi_replace(): REG_EMPTY:çempty (sub)expression in D:\sid\dg\test.php on line 2 Any ideas? BTW any place where I can get started on regex? I got a perl book that explains regex, but I have got to learn perl first (I dont know any perl) Thanks in advance. - Sid Sid a écrit: Hello, Well I am doing by first reg ex operations and I am having problems which I just cannot figure out. For example I tried echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font size=\2\\s*purchasing power parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1tdfont size=2Purchasing power parity'); and this worked perfectly, but when I chnaged that to echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font
[PHP] Re: Regex Help with - ?
looks like id3v2 ;-) how about this: $string = [TIT2] ABC [TPE1] GHI [TALB] XYZ; $pattern = /\[TIT2\]([^]*)/; // matches anything exept ''; till '' or end of string preg_match($pattern, $string, $match); var_export($match); hint to your regex: either use quantifier '*' (0-n times) OR '?' (0-1 times) ciao SVEN Gerard Samuel [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] I have a string something like - [TIT2] ABC [TPE1] GHI [TALB] XYZ Im applying a regex as such - // Title/Songname/Content preg_match('/\[TIT2\](.*?)(\[)?/', $foo, $match); $title = trim( $match[1] ); The above regex doesn't work. At the end of the pattern Im using (\[)? The pattern may or may not end with [ For example searching for - [TALB] XYZ The string, is *NOT* expected to hold a certain order as how it is retrieved. How does one go about to fix up this regex? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex Help with - ?
sven wrote: looks like id3v2 ;-) how about this: $string = [TIT2] ABC [TPE1] GHI [TALB] XYZ; $pattern = /\[TIT2\]([^]*)/; // matches anything exept ''; till '' or end of string preg_match($pattern, $string, $match); var_export($match); Yeah, Im trying to figure out a way to parse these tags. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regex help
?php $str = 'hi bmy friend/b! br / this message uses html entities a href=http://www.trini0.org;test/a!'; $str = preg_replace('/(a href=http:\/\/.*.*\/a)/', htmlspecialchars($1), $str); Maybe I'm missing something here, but can't you just do: $str = htmlspecialchars($str); -- 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] Re: Regex help
[EMAIL PROTECTED] (Stefen Lars) writes: In the Apache config file, we have the following directive: SetEnvIfNoCase Referer ^http://www.oursite.com/; local_ref=1 FilesMatch .(gif|jpg) Order Allow,Deny Allow from env=local_ref /FilesMatch We use this to prevent people from directly linking to .gif and .jpg files. However, we have to add more and more file types to the FilesMatch directive. Currently it looks like this: FilesMatch .(doc|zip|xls|exe|jpg|gif|png|psd|tif|tif) However, this list continues to grow. And we can never be sure that every file type is included. It occurred to me that it would be better to say do not serve any files except .htm, .html and .php files.. I have spent quite a long time with several regexes, but I am unable to create a regex that archives this seemingly simple talk. How about this approach? SetEnvIfNoCase Referer ^http://www.oursite.com/; local_ref=1 Order Allow,Deny Allow from env=local_ref FilesMatch \.(php|html?)$ Allow from all /FilesMatch I'd tighten up your regex slightly too. As it was it would match pretty much any filename with those letters in it; The '.' matches any character and it's not anchored to the end of the string. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]