[PHP] Regex help please
I'm normally OK with regex, especially if I fiddle with it long enough, however I have fiddled with this one so long that I'm either totally missing it or it's something simple. Does it have anything to do with the backref, or the fact that the value of the backref has a $? I have: $out = ' {$sites} tr td {Site.id} /td /tr {/$sites}'; And I want to capture the first {$tag}, everything in between and the last {$/tag}. I have tried several things and here is my current regex that looks like it should work, but doesn't: preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches); Gives: Array ( [0] = Array ( ) [1] = Array ( ) [2] = Array ( ) [3] = Array ( ) ) -- 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] Regex help please
On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie nos...@mckenzies.net wrote: I'm normally OK with regex, especially if I fiddle with it long enough, however I have fiddled with this one so long that I'm either totally missing it or it's something simple. Does it have anything to do with the backref, or the fact that the value of the backref has a $? I have: $out = ' {$sites} tr td {Site.id} /td /tr {/$sites}'; And I want to capture the first {$tag}, everything in between and the last {$/tag}. I have tried several things and here is my current regex that looks like it should work, but doesn't: preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches); Shawn, First thing I see--your first capture group doesn't include the $, and so your final capture group will always fail given your current $out (because it's looking for {/sites} instead of {/$sites}). Also, your {} are outside of your capture group in \1, but inside in \3. Here's what I came up with: $out = ' {$sites} tr td {Site.id} /td /tr {/$sites}'; $matches = array(); preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches); print_r($matches); Produces this: Array ( [0] = Array ( [0] = {$sites} tr td {Site.id} /td /tr {/$sites} ) [1] = Array ( [0] = $sites ) [2] = Array ( [0] = tr td {Site.id} /td /tr ) [3] = Array ( [0] = /$sites ) ) Keep in mind, I had to view the page source in order to see the HTML tags, but it showed me everything I expected to see. HTH, -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help please
haliphax wrote: On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie nos...@mckenzies.net wrote: I'm normally OK with regex, especially if I fiddle with it long enough, however I have fiddled with this one so long that I'm either totally missing it or it's something simple. Does it have anything to do with the backref, or the fact that the value of the backref has a $? I have: $out = ' {$sites} tr td {Site.id} /td /tr {/$sites}'; And I want to capture the first {$tag}, everything in between and the last {$/tag}. I have tried several things and here is my current regex that looks like it should work, but doesn't: preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches); Shawn, First thing I see--your first capture group doesn't include the $, and so your final capture group will always fail given your current $out (because it's looking for {/sites} instead of {/$sites}). Also, your {} are outside of your capture group in \1, but inside in \3. Here's what I came up with: $out = ' {$sites} tr td {Site.id} /td /tr {/$sites}'; $matches = array(); preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches); print_r($matches); Produces this: Array ( [0] = Array ( [0] = {$sites} tr td {Site.id} /td /tr {/$sites} ) [1] = Array ( [0] = $sites ) [2] = Array ( [0] = tr td {Site.id} /td /tr ) [3] = Array ( [0] = /$sites ) ) Keep in mind, I had to view the page source in order to see the HTML tags, but it showed me everything I expected to see. HTH, Yes, thank you. I was fiddling before I got your post and I came up with roughly the same. preg_match_all('|{(\$[^}]+)}(.+){(/\1)}|Us', $out, $matches); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
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] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
-Original Message- From: Jason Pruim [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 09, 2008 7:30 AM To: PHP-General List Subject: [PHP] Regex help 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 :) http://www.regular-expressions.info ... that's how I learned. :) Anyway... your match might be something like: ^/([^/\.]+)/?$ And the rewrite... /p.php?purl=$1 To break it down, the match is looking for The beginning of the line, followed by a forward slash, followed by (begin capture group) 1 or more characters that are not a forward slash or a period (end capture group) followed by an optional forward slash, followed by the end of the line. The rewrite is fairly straightforward. I went 100% generic with the match due to your following e-mail that stated jasonpruim112 could be any username. If 112 is necessary for the match, it would be more like: ^/([^/\.]+112)/?$ Hope this helps, Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help for URL's [ANSWER]
On May 16, 2006, at 7:53 PM, Chrome wrote: -Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:42 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] That's what I was doing. I was parsing A:HREF, IMG:SRC, etc. But when I implemented a new feature on my network, where you could click on a row and have it take you to another domain, I need a better solution. Go to http://www.enetwizard.ws and it might make more sense. All the links on the left have an ONCLICK=location.href = '' attribute in the TR tag. This solution allowed me to make sure those links included the session information, just like the A:HREF links do. It also had the advantage of updating the links in my CSS. O that breaks accessibility standards! Compliment the 'onclick's with onkeydown at least :) But still you get a solid onclick=... scenario If these are visible in the source then they are fairly easy to pick out Though you may need more than 1 regex ;) My complaint here is, don't break accessibility :) And don't forget the folks who have javascript turned off or are using text based browsers too. Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help for URL's
This one time, at band camp, Robert Samuel White [EMAIL PROTECTED] wrote: Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? Sorry, I missed most of this... From what I gather you wish to extract urls from text? if so.. function getLinks($string){ // regex to get the links preg_match_all(|http:?([^\' ]+)|i, $string, $arrayoflinks); return $arrayoflinks; } Also check out this on line tutorial for regex geared towards PHP http://phpro.org/tutorials/Introduction-to-PHP-Regular-Expressions.html Kind regards Kevin -- Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex Help for URL's
Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help for URL's
Robert Samuel White wrote: Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! so your looking for a regular expression that is *totally* different from the regular expression you have... the two have nothing in common. do you expect us to do the complete rewrite for you or do you want to learn abit about regexps yourself? (that probably sounds arrogant, so it might help to know even the most experienced people (a group I don't consider myself part of) here have [and do] get told to RTFM on occasion - no one is safe ;-) I suggest using a search engine to start with and see what that turns up... somehow I can't believe that nobody has ever written a regexp that matches urls, for instance try reading this page in the manual (hint: look at the the user notes) http://php.net/preg_match come back when/if you get stuck. preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's
Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 4:28 PM To: Robert Samuel White Cc: php-general@lists.php.net Subject: Re: [PHP] Regex Help for URL's Robert Samuel White wrote: Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! so your looking for a regular expression that is *totally* different from the regular expression you have... the two have nothing in common. do you expect us to do the complete rewrite for you or do you want to learn abit about regexps yourself? (that probably sounds arrogant, so it might help to know even the most experienced people (a group I don't consider myself part of) here have [and do] get told to RTFM on occasion - no one is safe ;-) I suggest using a search engine to start with and see what that turns up... somehow I can't believe that nobody has ever written a regexp that matches urls, for instance try reading this page in the manual (hint: look at the the user notes) http://php.net/preg_match come back when/if you get stuck. preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's
On Tue, 2006-05-16 at 16:31, Robert Samuel White wrote: Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? Perhaps a tad rude, but I got a treasure trove of hits from Google in my first shot: http://www.google.ca/search?hl=enq=regex+extract+urls+from+contentbtnG=Google+Searchmeta= Formulating a good search query is a great skill to hone. 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
Re: [PHP] Regex Help for URL's
Robert Samuel White wrote: Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? What's simple is a Google search. If you don't want to do the leg work, don't ask us to do it for. Simple enough, don't you think. Because it makes the email hard to read. Why is top posting bad? -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 4:28 PM To: Robert Samuel White Cc: php-general@lists.php.net Subject: Re: [PHP] Regex Help for URL's Robert Samuel White wrote: Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! so your looking for a regular expression that is *totally* different from the regular expression you have... the two have nothing in common. do you expect us to do the complete rewrite for you or do you want to learn abit about regexps yourself? (that probably sounds arrogant, so it might help to know even the most experienced people (a group I don't consider myself part of) here have [and do] get told to RTFM on occasion - no one is safe ;-) I suggest using a search engine to start with and see what that turns up... somehow I can't believe that nobody has ever written a regexp that matches urls, for instance try reading this page in the manual (hint: look at the the user notes) http://php.net/preg_match come back when/if you get stuck. preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's
I am trying to get all of the urls in a web document, so that I can append information to the urls when needed (when the url points to a domain that resides on my server). It allows me to pass session information across the domains of my network. Currently, I use a class I wrote to handle this, but it only works when it finds the urls in a standard html tag. I need to expand upon this, so that it also finds urls that are in onclick events, for example. Here is a sample page from my website: SCRIPT LANGUAGE=JavaScriptif (parent != self) top.location.href = location.href;/SCRIPTTABLE WIDTH=1000 BORDER=0 CELLPADDING=0 CELLSPACING=0 ALIGN=CENTER CLASS=TEMPLATE-TABLETRTD COLSPAN=7 CLASS=TEMPLATE-TABLE-TOP TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100% HEIGHT=48 TR TD WIDTH=60 ROWSPAN=2 ALIGN=RIGHTIMG SRC=http://www.enetwizard.info/shared/enetwizard.gif; WIDTH=46 HEIGHT=46 BORDER=0 ALT= //TD TD HEIGHT=24 VALIGN=BOTTOMDIV STYLE=font-family: sans-serif; font-size: 8pt; font-weight: bold; color: white; margin-left: 10px;eNetwizard, Inc./DIV/TD TD HEIGHT=24 VALIGN=BOTTOM ALIGN=RIGHTDIV STYLE=font-family: sans-serif; font-size: 8pt; color: #FF; font-weight: bold; margin-right: 20px; Anonymous Visitornbsp;nbsp;|nbsp;nbsp;A HREF=http://www.enetwizard.cc/security.wizard?asset=welcomeamp;process=log inamp;form=login STYLE=font-family: sans-serif; font-size: 8pt; color: #6BDB17; font-weight: bold; text-decoration: underline;Log In/Anbsp;nbsp;|nbsp;nbsp;A HREF=http://www.enetwizard.cc/security.wizard?asset=welcomeamp;process=sig nupamp;form=signup STYLE=font-family: sans-serif; font-size: 8pt; color: #6BDB17; font-weight: bold; text-decoration: underline;Sign Up/A /DIV/TD /TRTR TD HEIGHT=24 VALIGN=TOPDIV STYLE=font-family: sans-serif; font-size: 8pt; color: white; margin-left: 10px;IEmpowering Your Creativity./I/DIV/TD TD HEIGHT=24 VALIGN=TOP ALIGN=RIGHTDIV STYLE=font-family: sans-serif; font-size: 8pt; color: #FF; margin-right: 20px; ITuesday, May 16, 2006/I /DIV/TD /TR /TABLE /TD/TRTRTD COLSPAN=7 STYLE=height: 20px;DIV STYLE=font-size: 1px;nbsp;/DIV/TD/TRTRTD VALIGN=TOP STYLE=width: 20px;DIV STYLE=font-size: 1px;nbsp;/DIV/TDTD VALIGN=TOP CLASS=TEMPLATE-TABLE-LEFT STYLE=width: 180px;TABLE CLASS=RSW-TABLETR CLASS=RSW-TABLE-HEAD-TRTD CLASS=RSW-TABLE-HEAD-TDDIV CLASS=RSW-DIV-HEAD-CENTERSPAN CLASS=RSW-FONT-HEAD-TEXTeNetwizard, Inc./SPAN/DIV/TD/TRTR CLASS=RSW-TABLE-ROW1-TRTD CLASS=RSW-TABLE-ROW1-TD ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status = 'Backend Manager'; return true; ONMOUSEOUT=this.className = 'RSW-TABLE-ROW1-TD'; window.status = ''; return true; ONCLICK=location.href = 'http://www.enetwizard.be/default.rsw'; return true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-ROW1-LEFTSPAN CLASS=RSW-FONT-ROW1-TEXTA CLASS=RSW-FONT-ROW1-LINK HREF=http://www.enetwizard.be/default.rsw; ONMOUSEOVER=window.status = 'Backend Manager'; return true; ONMOUSEOUT=window.status = ''; return true;Backend Manager/ABReNetwizard.be/SPAN/DIV/TD/TRTR CLASS=RSW-TABLE-ROW2-TRTD CLASS=RSW-TABLE-ROW2-TD ONMOUSEOVER=this.className = 'RSW-TABLE-SEP2-TD'; window.status = 'Business Headquarters'; return true; ONMOUSEOUT=this.className = 'RSW-TABLE-ROW2-TD'; window.status = ''; return true; ONCLICK=location.href = 'http://www.enetwizard.biz/default.rsw'; return true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-ROW2-LEFTSPAN CLASS=RSW-FONT-ROW2-TEXTA CLASS=RSW-FONT-ROW2-LINK HREF=http://www.enetwizard.biz/default.rsw; ONMOUSEOVER=window.status = 'Business Headquarters'; return true; ONMOUSEOUT=window.status = ''; return true;Business Headquarters/ABReNetwizard.biz/SPAN/DIV/TD/TRTR CLASS=RSW-TABLE-SEP1-TRTD CLASS=RSW-TABLE-SEP1-TD ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status = 'Client Control Center'; return true; ONMOUSEOUT=this.className = 'RSW-TABLE-SEP1-TD'; window.status = ''; return true; ONCLICK=location.href = 'http://www.enetwizard.cc/default.rsw'; return true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-SEP1-LEFTSPAN CLASS=RSW-FONT-SEP1-TEXTA CLASS=RSW-FONT-SEP1-LINK HREF=http://www.enetwizard.cc/default.rsw; ONMOUSEOVER=window.status = 'Client Control Center'; return true; ONMOUSEOUT=window.status = ''; return true;Client Control Center/ABReNetwizard.cc/SPAN/DIV/TD/TRTR CLASS=RSW-TABLE-ROW2-TRTD CLASS=RSW-TABLE-ROW2-TD ONMOUSEOVER=this.className = 'RSW-TABLE-SEP2-TD'; window.status = 'Development Services'; return true; ONMOUSEOUT=this.className = 'RSW-TABLE-ROW2-TD'; window.status = ''; return true; ONCLICK=location.href = 'http://www.enetwizard.de/default.rsw'; return true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-ROW2-LEFTSPAN CLASS=RSW-FONT-ROW2-TEXTA CLASS=RSW-FONT-ROW2-LINK HREF=http://www.enetwizard.de/default.rsw; ONMOUSEOVER=window.status = 'Development Services'; return true; ONMOUSEOUT=window.status = ''; return true;Development Services/ABReNetwizard.de/SPAN/DIV/TD/TRTR CLASS=RSW-TABLE-ROW1-TRTD CLASS=RSW-TABLE-ROW1-TD ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status =
Re: [PHP] Regex Help for URL's
Robert Samuel White wrote: Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? I wasn't being rude. Although even If I was commanding me stop is rather futile no? if I was being rude I would have said something like: read http://php.net/preg_match and find the get_links() function posted by 'max99x [at] gmail [dot] com' you f*** wit now that would have been rude. the argument that the length of time spent programming automatically makes you 'not a slacker' is unbased. one does not equate the other. personally I would assume anyone who had been programming for 20 yrs would have a reasonable understanding of regexps. -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 4:28 PM To: Robert Samuel White Cc: php-general@lists.php.net Subject: Re: [PHP] Regex Help for URL's Robert Samuel White wrote: Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! so your looking for a regular expression that is *totally* different from the regular expression you have... the two have nothing in common. do you expect us to do the complete rewrite for you or do you want to learn abit about regexps yourself? (that probably sounds arrogant, so it might help to know even the most experienced people (a group I don't consider myself part of) here have [and do] get told to RTFM on occasion - no one is safe ;-) I suggest using a search engine to start with and see what that turns up... somehow I can't believe that nobody has ever written a regexp that matches urls, for instance try reading this page in the manual (hint: look at the the user notes) http://php.net/preg_match come back when/if you get stuck. preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's
-Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 16 May 2006 21:32 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's Don't be rude. I've already don't all of that. Nothing came up. I've been programming for 20 years (since I was 11 years old) so I'm not a slacker when it comes to learning new things, however, I have always found regular expressions to be extremely difficult. Someone here might have the answer I need, and if so, I'd appreciate a response. If you don't know the answer, don't reply. Simple enough, don't you think? -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 4:28 PM To: Robert Samuel White Cc: php-general@lists.php.net Subject: Re: [PHP] Regex Help for URL's Robert Samuel White wrote: Can someone help me modify the following code? It was designed to search for all instances of [LEVEL#]...[/LEVEL#] I need a preg_match_all that will search for all of instances of an URL. It should be sophisticated enough to find something as complicated as this: http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor Any help would be greatly appreciated! so your looking for a regular expression that is *totally* different from the regular expression you have... the two have nothing in common. do you expect us to do the complete rewrite for you or do you want to learn abit about regexps yourself? (that probably sounds arrogant, so it might help to know even the most experienced people (a group I don't consider myself part of) here have [and do] get told to RTFM on occasion - no one is safe ;-) I suggest using a search engine to start with and see what that turns up... somehow I can't believe that nobody has ever written a regexp that matches urls, for instance try reading this page in the manual (hint: look at the the user notes) http://php.net/preg_match come back when/if you get stuck. preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent, $tmpMatches); $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', '###URL###', $arcContent); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ NOD32 1.1541 (20060516) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com Bearing in mind that none of the replies (particularly that of Jochem, one of the posters that should be held in high regard) have been rude in any way at all, I understand your plight with regex's You might want to try the Regex Coach... It allows you to test your regex's offline and can really help http://www.weitz.de/regex-coach/ HTH Dan Personal note: Stop using Lookout... it sucks -- http://chrome.me.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
In case any one is looking for a solution to a similar problem as me, here is the answer. I used the code from my original post as my guiding light, and with some experimentation, I figured it out. To get any URL, regardless of where it is located, use this: preg_match_all(#\'http://(.*)\'#U, $content, $matches); This match anything similar to: 'http://www.domain.com/dir/dir/file.txt?query=blah' This is useful, if for example, you have a tag like this one: A HREF=javascript:void(0); ONCLICK=javascript:window.open = 'http://www.domain.com/dir/dir/file.txt?query=blah'; Now, for tags which are in quotes, rather than single quotes, just use: preg_match_all(#\http://(.*)\#U, $content, $matches); This is really only the first step. In order to be useful, you need a way to process these urls according to your own specific needs: preg_match_all(#\'http://(.*)\'#U, $content, $matches); $content = preg_replace(#\'http://(.*)\'#U, '###URL###', $content); This will modify the $content variable to change all urls to ###URL### You can then go through them one at a time to process them: for ($count = 0; $count count($matches[1]); $count++) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
On Tue, 2006-05-16 at 18:49, Robert Samuel White wrote: In case any one is looking for a solution to a similar problem as me, here is the answer. I used the code from my original post as my guiding light, and with some experimentation, I figured it out. To get any URL, regardless of where it is located, use this: preg_match_all(#\'http://(.*)\'#U, $content, $matches); This match anything similar to: 'http://www.domain.com/dir/dir/file.txt?query=blah' This is useful, if for example, you have a tag like this one: A HREF=javascript:void(0); ONCLICK=javascript:window.open = 'http://www.domain.com/dir/dir/file.txt?query=blah'; Now, for tags which are in quotes, rather than single quotes, just use: preg_match_all(#\http://(.*)\#U, $content, $matches); I'd roll those two into one expression: preg_match_all(#(\|')http://(.*)(\|')#U, $content, $matches); 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
RE: [PHP] Regex Help for URL's [ANSWER]
On Tue, May 16, 2006 6:21 pm, Robert Cummings wrote: On Tue, 2006-05-16 at 18:49, Robert Samuel White wrote: In case any one is looking for a solution to a similar problem as me, here preg_match_all(#(\|')http://(.*)(\|')#U, $content, $matches); And it's missing the original requirement of matching https URLs, so maybe make it be ...https?://... Plus, http could be IN CAPS, so change the U to iU And, actually, SOME old-school HTML pages will have neither ' nor around the URL, and are (or were) valid: href=page2.html was considered valid for HTML for a long long long time So toss in (\|')? And then you may be finding URLs that are not actually linked but are part of the visible content, so maybe you only want the ones that have a[^]href= in front of them. If I can toss off 3 problems without even trying... So I still think Google or searching the archives (as I suggested off-list) will be the quickest route to a CORRECT answer, but here we are again in this same thread we've been in every month or so for the better part of a decade... PS the (\|') bit may move the URLs into $matches[2] instead of $matches[1] or whatever. -- 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] Regex Help for URL's [ANSWER]
All pages used by my content management system must be in a valid format. Old-school style pages are never created so the solution I have come up with is perfect for my needs. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
-Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:16 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] All pages used by my content management system must be in a valid format. Old-school style pages are never created so the solution I have come up with is perfect for my needs. Thank you. Doesn't that make it a proprietary solution? IMHO offering the regex may create a false situation for people... So the answer may not be for everyone Might be wrong :) Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help for URL's
On Tue, May 16, 2006 4:22 pm, Jochem Maas wrote: personally I would assume anyone who had been programming for 20 yrs would have a reasonable understanding of regexps. Nope. :-) I got WAY past 20 year mark before I even began to pretend to understand the minimal amount of regex I can do now. Most things complicated enough to need regex are too complicated to do with regex, if you know what I mean... There's a very narrow band of problems where I'm comfy with regex, really. Anything simpler than that is just a substr or explode. Anything more complicated, and I just don't want to try to maintain the mess of not-quite-random characters needed to make a so-called pattern and I'll find some other way to break the problem down into sub-problems. Those sub-problems might then be amenable to a reasonable regex, of course, but I'm just not gonna tackle it in one big messy pattern. -- 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] Regex Help for URL's [ANSWER]
In my opinion, it is the most reasonable solution. I have looked all over the web for something else, but this works perfectly for me. It's impossible to tell where an url starts and ends if you don't have it in quotes or single quotes. If someone really needs to find all the urls in a page, then they'll code their pages to make use of this limitation. -Original Message- From: Chrome [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 8:24 PM To: 'Robert Samuel White'; php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] -Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:16 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] All pages used by my content management system must be in a valid format. Old-school style pages are never created so the solution I have come up with is perfect for my needs. Thank you. Doesn't that make it a proprietary solution? IMHO offering the regex may create a false situation for people... So the answer may not be for everyone Might be wrong :) Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
-Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:28 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] In my opinion, it is the most reasonable solution. I have looked all over the web for something else, but this works perfectly for me. It's impossible to tell where an url starts and ends if you don't have it in quotes or single quotes. If someone really needs to find all the urls in a page, then they'll code their pages to make use of this limitation. -Original Message- From: Chrome [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 8:24 PM To: 'Robert Samuel White'; php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] -Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:16 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] All pages used by my content management system must be in a valid format. Old-school style pages are never created so the solution I have come up with is perfect for my needs. Thank you. Doesn't that make it a proprietary solution? IMHO offering the regex may create a false situation for people... So the answer may not be for everyone Might be wrong :) Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ NOD32 1.1542 (20060516) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com If we are talking clickable links, why not focus on the a construct itself? Otherwise URLs are just part of the page's textual content... Very difficult to parse that Disseminating an a tag isn't brain-meltingly difficult with a regex if you put your mind to it... With or without quotes, be they single, double or non-existent If I've misunderstood please chastise me :) HTH Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
If we are talking clickable links, why not focus on the a construct itself? Otherwise URLs are just part of the page's textual content... Very difficult to parse that Disseminating an a tag isn't brain-meltingly difficult with a regex if you put your mind to it... With or without quotes, be they single, double or non-existent If I've misunderstood please chastise me :) HTH Dan Dan, That's what I was doing. I was parsing A:HREF, IMG:SRC, etc. But when I implemented a new feature on my network, where you could click on a row and have it take you to another domain, I need a better solution. Go to http://www.enetwizard.ws and it might make more sense. All the links on the left have an ONCLICK=location.href = '' attribute in the TR tag. This solution allowed me to make sure those links included the session information, just like the A:HREF links do. It also had the advantage of updating the links in my CSS. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help for URL's [ANSWER]
-Original Message- From: Robert Samuel White [mailto:[EMAIL PROTECTED] Sent: 17 May 2006 01:42 To: php-general@lists.php.net Subject: RE: [PHP] Regex Help for URL's [ANSWER] If we are talking clickable links, why not focus on the a construct itself? Otherwise URLs are just part of the page's textual content... Very difficult to parse that Disseminating an a tag isn't brain-meltingly difficult with a regex if you put your mind to it... With or without quotes, be they single, double or non-existent If I've misunderstood please chastise me :) HTH Dan Dan, That's what I was doing. I was parsing A:HREF, IMG:SRC, etc. But when I implemented a new feature on my network, where you could click on a row and have it take you to another domain, I need a better solution. Go to http://www.enetwizard.ws and it might make more sense. All the links on the left have an ONCLICK=location.href = '' attribute in the TR tag. This solution allowed me to make sure those links included the session information, just like the A:HREF links do. It also had the advantage of updating the links in my CSS. O that breaks accessibility standards! Compliment the 'onclick's with onkeydown at least :) But still you get a solid onclick=... scenario If these are visible in the source then they are fairly easy to pick out Though you may need more than 1 regex ;) My complaint here is, don't break accessibility :) Dan -- http://chrome.me.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On Fri, Jan 13, 2006 at 08:25:57AM -0500, Mike Smith wrote: I'm trying to save myself some time by extracting certain variables from a string: 102-90 E 42 X 42 X 70 3/8 I've been testing with: http://www.quanetic.com/regex.php and have been somewhat successful. Using this pattern: /[0-9]{2,}( X| x|x )/ The biggest problem with trying to match a string with regex is you have to know the definition of what the string can be, for example can the data be: 102-90 E 42 X 42 X 70 3/8 102-90 E 42 X 42 X 70 3/8 102-90 E 42X42X70 3/8 102-90 E 42\tX\t 42 \t X\n 70\r\n 3/8 I have: 102-90 E [!MATCH!] [!MATCH!] 70 3/8 If you want to just match those two numbers then: /\s+(\d{1,2})\s+(X|x)\s+(\d{1,2})\s+(X|x)\s+/ Ideally what I want to do is update the db table that holds these records. ID: 1 Unit: 102-90 E 42 X 42 X 70 3/8 Panel: 42 Width: 42 Height: 70 3/8 If this is the case, where does the 102-90 E come from? This sounds more like a data normalization issue than anything. Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
I'm trying to save myself some time by extracting certain variables from a string: 102-90 E 42 X 42 X 70 3/8 I've been testing with: http://www.quanetic.com/regex.php and have been somewhat successful. Using this pattern: /[0-9]{2,}( X| x|x )/ I have: 102-90 E [!MATCH!] [!MATCH!] 70 3/8 Ideally what I want to do is update the db table that holds these records. ID: 1 Unit: 102-90 E 42 X 42 X 70 3/8 Panel: 42 Width: 42 Height: 70 3/8 $pattern1 = '/[0-9]{2,}( X| x|x )/'; $units = array of units above foreach($units AS $unit){ preg_match($pattern1,$unit[1],$match); print_r($match); echo Panel: .$match[0]; } The $match array is empty. Actually looking at the data there are so many typos (imported from Excel) that I will probably have to update by hand, but out of curiosity now what would be a good regex for the info given? Thanks, Mike Smith -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
Mike Smith wrote: I'm trying to save myself some time by extracting certain variables from a string: 102-90 E 42 X 42 X 70 3/8 If this string is always in this format xxx E panel X width X height then you could try something like: // Very much untested $unit = '102-90 E 42 X 42 X 70 3/8'; $split1 = explode('E', $unit); list($panel, $width, $height) = explode('X', $split1[1]); Albert -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.371 / Virus Database: 267.14.17/228 - Release Date: 2006/01/12 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
This should do the trick: /(\d+) ?X ?(\d+) ?X ?(\d+ [\d\/]+)/i (at least it would in Perl) Le 13 Janvier 2006 08:25, Mike Smith a écrit : I'm trying to save myself some time by extracting certain variables from a string: 102-90 E 42 X 42 X 70 3/8 I've been testing with: http://www.quanetic.com/regex.php and have been somewhat successful. Using this pattern: /[0-9]{2,}( X| x|x )/ I have: 102-90 E [!MATCH!] [!MATCH!] 70 3/8 Ideally what I want to do is update the db table that holds these records. ID: 1 Unit: 102-90 E 42 X 42 X 70 3/8 Panel: 42 Width: 42 Height: 70 3/8 $pattern1 = '/[0-9]{2,}( X| x|x )/'; $units = array of units above foreach($units AS $unit){ preg_match($pattern1,$unit[1],$match); print_r($match); echo Panel: .$match[0]; } The $match array is empty. Actually looking at the data there are so many typos (imported from Excel) that I will probably have to update by hand, but out of curiosity now what would be a good regex for the info given? Thanks, Mike Smith -- Eric Martel Sainte-Foy (Québec) Canada Ce courriel est signé numériquement avec la clef suivante: This e-mail is digitally signed with the following key: ED3F191C (key://pgp.mit.edu, http://key.ericmartel.net/) Empreinte/fingerprint: 023D EFB7 8957 CBC0 C4E7 243D F01E D8A8 ED3F 191C Pour plus d'information: http://gpg.ericmartel.net/ For more info: http://kmself.home.netcom.com/Rants/gpg-signed-mail.html There are flaws in Windows so great that they would threaten national security if the Windows source code were to be disclosed. --Microsoft VP Jim Allchin, under oath The intrinsic parallelism and free idea exchange in open source software has benefits that are not replicable with our current licensing model. --Microsoft Read more on http://opensource.org/halloween/ Read between lines: get Linux! It's free, open source, more secure, more reliable and more performant than Window$. http://www.linuxiso.org/ pgpL8YrMZ420Z.pgp Description: PGP signature
Re: [PHP] Regex help
Eric, thanks for replying. I couldn't quite get that to work. Albert, I'm currently working with what you suggested, though the unit names are not that consistent: $vals = preg_split(' ?X? ',$unit[1]); echo strong.$unit[1]./strongbr /\n; echo Panel: .$vals[0].br /Width: .$vals[1].br /Height: .$vals[2].br /\n; 202-90B 48 X 48 X 69 1/4 Panel: 202-90B 48 Width: 48 Height: 69 1/4 Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
Why isn't this regular expression ^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$ allowing for this value: 'Co. Dublin' (w/o the single quotes) ? It's failing the regular expression match... thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On Fri, 2005-11-18 at 10:55, Chris Boget wrote: Why isn't this regular expression ^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$ allowing for this value: 'Co. Dublin' (w/o the single quotes) ? It's failing the regular expression match... Do you have that expression embedded in single or double quotes? Please show us the actual context. 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
Re: [PHP] Regex help
Chris, if (preg_match(/^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$/, Co. Dublin)) echo TRUE; else echo FALSE; prints TRUE for me. Cheers, David Grant Chris Boget wrote: Why isn't this regular expression ^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$ allowing for this value: 'Co. Dublin' (w/o the single quotes) ? It's failing the regular expression match... thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex Help
Hi, folks. I'm having trouble with a simple regex. I'm sure it's just something small that I'm missing but nothing I'm trying is working. In an HTML file I have comments like this: !-- START PRINT -- various html crap here !-- END PRINT -- Here's the regex I'm using: /!-- START PRINT --(.*?)!-- END PRINT --/ And then the call to preg_match_all(): preg_match_all($printable_reg, $str, $out); It's been quite a while since I've worked with regular expressions so I'm not sure what the problem is. The regex isn't throwing errors, it's just not matching the content located between the start print and end print comments. Can anyone lend a hand or give some advice? Cheers and TIA, Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help
Hi, folks. I'm having trouble with a simple regex. I'm sure it's just something small that I'm missing but nothing I'm trying is working. In an HTML file I have comments like this: !-- START PRINT -- various html crap here !-- END PRINT -- Here's the regex I'm using: /!-- START PRINT --(.*?)!-- END PRINT --/ And then the call to preg_match_all(): preg_match_all($printable_reg, $str, $out); It's been quite a while since I've worked with regular expressions so I'm not sure what the problem is. The regex isn't throwing errors, it's just not matching the content located between the start print and end print comments. Can anyone lend a hand or give some advice? I'm thinking that perhaps you want to add the s modifier to your pattern... From http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help
Hi, folks. I'm having trouble with a simple regex. I'm sure it's just something small that I'm missing but nothing I'm trying is working. In an HTML file I have comments like this: !-- START PRINT -- various html crap here !-- END PRINT -- Here's the regex I'm using: /!-- START PRINT --(.*?)!-- END PRINT --/ And then the call to preg_match_all(): preg_match_all($printable_reg, $str, $out); It's been quite a while since I've worked with regular expressions so I'm not sure what the problem is. The regex isn't throwing errors, it's just not matching the content located between the start print and end print comments. Can anyone lend a hand or give some advice? Hi Pablo, At a (reasonable) guess, I'd say it's because you're not using the s pattern modifier in your preg_match_all()? The s modifier forces your regular expression to match new lines with the . metacharacter. Try: preg_match_all(/!-- START PRINT --(.*?)!-- END PRINT --/s, $str, $out); http://php.planetmirror.com/manual/en/reference.pcre.pattern.modifiers.php Hope this helps. Much warmth, Murray --- Lost in thought... http://www.planetthoughtful.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex Help
Greetings folks. Thanks Murray and Philip for the quick responses. Adding the /s modifier worked perfectly. Cheers, Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] REGEX Help Please
Hi, 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}/; Can anyone help here please? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REGEX Help Please
Shaun wrote: Hi, 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}/; Can anyone help here please? Thanks May have to go outside just a regex... if ( preg_match ( /^\d{1}\.\d{2}$/, $number ) $number = 0 $number = 1 ) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REGEX Help Please
On Mon, 2005-09-19 at 10:11, John Nichel wrote: Shaun wrote: Hi, 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}/; Can anyone help here please? Thanks May have to go outside just a regex... if ( preg_match ( /^\d{1}\.\d{2}$/, $number ) $number = 0 $number = 1 ) $regexp = '/^((1\.00)|(0\.\d\d))$/'; 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
Re: [PHP] REGEX Help Please
On Monday 19 September 2005 09:03 am, Shaun wrote: Hi, 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}/; Can anyone help here please? Thanks $regexp = /^(0\.[0-9]{2}|1\.00)/; that should work :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On 8/4/05, Lizet Pena de Sola [EMAIL PROTECTED] wrote: Ok, it's not the regexp for detecting email addresses what I need, that's widely published, thanks. I'm using ereg to match this regular expression: (On)[\s\w\d\W\S\D\n]*(wr[i|o]te[s]?:) That will match phrases like On 8/3/05, Carol Swinehart [EMAIL PROTECTED] wrote: the type On date, name email wrote or writes: The thing is I tried this regexp with Regex Coach and it matches fine, but ereg returns no match ereg($regexpstr, $str, $regs) I know there are some comments at php.net about how ereg has some bugs, any idea if this could be one? Tia, Lizet You're not going to get far with that. Lots of people make 'funny' You Wrote lines, and not all of them start with 'On' or contain the word 'wr[o|i]te'. You might be better off just searching for any sentance that contains an @ sign, because they are very seldom used outside of email addresses nowadays. And that doesn't make any promises, either, because sometimes the whole email address isn't in the line, just the person's name. Dotan Cohen http://lyricslist.com/lyrics/artist_albums/286/judas_priest.php Judas Priest Song Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
Ok, it's not the regexp for detecting email addresses what I need, that's widely published, thanks. I'm using ereg to match this regular expression: (On)[\s\w\d\W\S\D\n]*(wr[i|o]te[s]?:) That will match phrases like On 8/3/05, Carol Swinehart [EMAIL PROTECTED] wrote: the type On date, name email wrote or writes: The thing is I tried this regexp with Regex Coach and it matches fine, but ereg returns no match ereg($regexpstr, $str, $regs) I know there are some comments at php.net about how ereg has some bugs, any idea if this could be one? Tia, Lizet -Original Message- From: Marcus Bointon [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 03, 2005 8:57 AM To: PHP General Subject: Re: [PHP] Regex help On 2 Aug 2005, at 15:12, Robin Vickery wrote: I don't suppose this is the place for a rant about the futility of checking email addresses with a regexp? Though I will agree with you to some extent, I've had quite a lot of success with this, which is pretty thorough: ^(?:[\w\!\#\$\%\\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\\'\*\+\- \/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61} [a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)| (?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4] \d|25[0-5])\]))$ Which I got from here: http://www.hexillion.com/samples/#Regex Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture [EMAIL PROTECTED] | http://www.synchromedia.co.uk -- 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] Regex help
On 2 Aug 2005, at 15:12, Robin Vickery wrote: I don't suppose this is the place for a rant about the futility of checking email addresses with a regexp? Though I will agree with you to some extent, I've had quite a lot of success with this, which is pretty thorough: ^(?:[\w\!\#\$\%\\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\\'\*\+\- \/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61} [a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)| (?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4] \d|25[0-5])\]))$ Which I got from here: http://www.hexillion.com/samples/#Regex Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture [EMAIL PROTECTED] | http://www.synchromedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
I'm trying to validate an email address and for the life of me I cannot figure out why the following regex is not working: script language=php $email = [EMAIL PROTECTED]; $regex = ^([a-zA-Z0-9_\.\-\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-\']+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$; if( ereg( $regex, $email )) { echo 'Good email address'; } else { echo 'Bad email address'; } /script Does anyone have any ideas? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On 8/2/05, Chris Boget [EMAIL PROTECTED] wrote: I'm trying to validate an email address and for the life of me I cannot figure out why the following regex is not working: $email = [EMAIL PROTECTED]; $regex = ^([a-zA-Z0-9_\.\-\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-\']+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$; [a-zA-Z0-9\-\'] You don't escape hyphens like that in a character class. Put it at the end of the list of characters like this: [a-zA-Z0-9'-] Then it'll match your test address. If you're trying to find out why a regexp isn't working, try simplifying your test cases until it works. For example: $email = [EMAIL PROTECTED]; // doesn't work $email = [EMAIL PROTECTED]; // doesn't work $email = [EMAIL PROTECTED]; // doesn't work $email = [EMAIL PROTECTED]; // works! I don't suppose this is the place for a rant about the futility of checking email addresses with a regexp? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On 8/2/05, Robin Vickery [EMAIL PROTECTED] wrote: I don't suppose this is the place for a rant about the futility of checking email addresses with a regexp? -robin Let Richard Lynch tell him. He's good at regex's, and it's HIS email address that never makes it through! Dotan Cohen http://lyricslist.com/lyrics/artist_albums/182/estefan_gloria.php Estefan, Gloria Song Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
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 reason you can't match everything from TAGINCAPS through the end of the line, then once you have that stored in a string, split it on :'s to extract the pieces you want? Even elements would be the tag, odd would be the value... just a thought. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RegEx help
I wanted to create a regex that force a PHP form text field to meet the following requirements: a. Must contain an 1 uppercase letter. [A-Z] b. Must contain 1 digit. [0-9] c. Must be a minimum of 7 characters in length. {7} I'm not sure of how to build the correct syntax for using all 3 requirements together. Any help? Thanks, Dave HTC Disclaimer: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.
Re: [PHP] RegEx help
On Thu, 14 Apr 2005, Bosky, Dave wrote: I wanted to create a regex that force a PHP form text field to meet the following requirements: a. Must contain an 1 uppercase letter. [A-Z] b. Must contain 1 digit. [0-9] c. Must be a minimum of 7 characters in length. {7} if ( ereg([A-Z0-9], $field) strlen($field) = 7 ) { print(We have a winner!); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegEx help
Philip Hallstrom wrote: On Thu, 14 Apr 2005, Bosky, Dave wrote: I wanted to create a regex that force a PHP form text field to meet the following requirements: a. Must contain an 1 uppercase letter. [A-Z] b. Must contain 1 digit. [0-9] c. Must be a minimum of 7 characters in length. {7} if ( ereg([A-Z0-9], $field) strlen($field) = 7 ) { print(We have a winner!); } nope, a username like 1234567 would go trough ok. Which isn't what he wanted -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegEx help
Hi, Thursday, April 14, 2005, 11:47:13 PM, you wrote: BD I wanted to create a regex that force a PHP form text field to meet the BD following requirements: BD a. Must contain an 1 uppercase letter. [A-Z] BD b. Must contain 1 digit. [0-9] BD c. Must be a minimum of 7 characters in length. {7} BD I'm not sure of how to build the correct syntax for using all 3 BD requirements together. BD Any help? BD Thanks, BD Dave BD HTC Disclaimer: The information contained in this message BD may be privileged and confidential and protected from disclosure. BD If the reader of this message is not the intended recipient, or an BD employee or agent responsible for delivering this message to the BD intended recipient, you are hereby notified that any BD dissemination, distribution or copying of this communication is BD strictly prohibited. If you have received this communication in BD error, please notify us immediately by replying to the message and BD deleting it from your computer. Thank you. easier done seperately I think if( strlen($text) 6 preg_match('/\d+/',$text) preg_match('/[A-Z]+/',$text) ) { echo 'OK br'; -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegEx help
I wanted to create a regex that force a PHP form text field to meet the following requirements: a. Must contain an 1 uppercase letter. [A-Z] b. Must contain 1 digit. [0-9] c. Must be a minimum of 7 characters in length. {7} if ( ereg([A-Z0-9], $field) strlen($field) = 7 ) { print(We have a winner!); } nope, a username like 1234567 would go trough ok. Which isn't what he wanted that's what I get for thinking too fast :) Seems like you should be able to do then um... ([A-Z]|[0-9]) as your regexp (check on escaping the ()'s or not. I can never remember) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RegEx help
On 15 Apr 2005 Tom Rogers wrote: BD a. Must contain an 1 uppercase letter. [A-Z] BD b. Must contain 1 digit. [0-9] BD c. Must be a minimum of 7 characters in length. {7} BD I'm not sure of how to build the correct syntax for using all 3 BD requirements together. easier done seperately I think if( strlen($text) 6 preg_match('/\d+/',$text) preg_match('/[A-Z]+/',$text) ) { echo 'OK br'; To do it in one fell swoop you need to use lookahead assertions -- something like this: if (preg_match('/(?=.*[A-Z])(?=.*[0-9]).{7,}/', $text)) echo 'Valid!'; I believe this matches for any string that has at least one uppercase letter and one digit and is at least 7 characters long. However it allows other characters as well (not just A-Z and 0-9). Lots of possible variations there. -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
[EMAIL PROTECTED] wrote: OK, this is off-topic like every other regex help post, but I know some of you enjoy these puzzles :) This isn't an exam question, is it? ;) 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? Yup, use this perl regex: /^(?:()(?!)|[^]){1,5}$/ Where 5 above is the maximum length of the string. You can change this to any positive value and the regex will still work. Basically it says look for 1 to 5 single characters where each either isn't an ampersand, or IS an ampersand but isn't immediately followed by an ampersand. The (?!) is a zero-width negative look-ahead assertion which is like other assertions such as \b that don't eat up the portions of the string that they match. Sample code, tested: $maxLen = 5; $testStrings = array( 'a', 'g', 'df', 'adfdf', 'adfsdfff', 'ff', 'dfds', 'dsdf', 'ddf', 'dff' ); foreach ($testStrings as $string) { if (preg_match(/^(?:()(?!)|[^]){1,$maxLen}$/, $string)) { print $string matches.\n; } else { print $string does not match.\n; } } Hope this helps you (pass your exam? ;) ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
On Sat, 2005-01-29 at 08:58, Michael Sims wrote: [EMAIL PROTECTED] wrote: OK, this is off-topic like every other regex help post, but I know some of you enjoy these puzzles :) This isn't an exam question, is it? ;) 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? Yup, use this perl regex: /^(?:()(?!)|[^]){1,5}$/ Where 5 above is the maximum length of the string. You can change this to any positive value and the regex will still work. Basically it says look for 1 to 5 single characters where each either isn't an ampersand, or IS an ampersand but isn't immediately followed by an ampersand. The (?!) is a zero-width negative look-ahead assertion which is like other assertions such as \b that don't eat up the portions of the string that they match. Great explanation. Thanks from one who has not had an exam for over ten years. Bret -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
Bret Hughes wrote: On Sat, 2005-01-29 at 08:58, Michael Sims wrote: [EMAIL PROTECTED] wrote: 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? Yup, use this perl regex: /^(?:()(?!)|[^]){1,5}$/ Great explanation. Thanks from one who has not had an exam for over ten years. Thanks...I actually just realized that the parentheses around the first ampersand are unnecessary (that was a leftover from a previous attempt), so this is simpler and will work just as well: /^(?:(?!)|[^]){1,5}$/ Or if you don't care about capturing portions of the match and then throwing them away: /^((?!)|[^]){1,5}$/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
Michael Sims wrote: 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. Yup, use this perl regex: /^(?:()(?!)|[^]){1,5}$/ [snip] Hope this helps you (pass your exam? ;) ) Thanks, Michael! I guess it is time for me to go review those zero-width negative look-ahead assertions - don't know how I missed them ;) And no, not an exam - this is real life. My days as a frolicking schoolboy are quite some distance behind me ;) Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On 28 Jan 2005 [EMAIL PROTECTED] wrote: 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. This is an example of something that is easier to do (and probably faster) without using a regexp: if ((strlen($str) = $maxlen) (strstr($str, '') === FALSE)) str is valid else str is not valid -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
[EMAIL PROTECTED] wrote on 01/28/2005 03:19:14 PM: On 28 Jan 2005 [EMAIL PROTECTED] wrote: 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. This is an example of something that is easier to do (and probably faster) without using a regexp: if ((strlen($str) = $maxlen) (strstr($str, '') === FALSE)) str is valid else str is not valid -- Tom Thanks, Tom. I agree, but not an option at this time - other parts of the design require this to be a regex. Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
[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. $text = $_REQUEST['text']; if (strlne($text) 42 !strstr($text, '')){ //kosher } else{ trigger_error(Invalid input, E_USER_ERROR); } Oh, wait, that's not Regex. Oh well. Too bad. -- 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] Regex help
[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote on 01/28/2005 03:19:14 PM: On 28 Jan 2005 [EMAIL PROTECTED] wrote: 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. This is an example of something that is easier to do (and probably faster) without using a regexp: if ((strlen($str) = $maxlen) (strstr($str, '') === FALSE)) str is valid else str is not valid -- Tom Thanks, Tom. I agree, but not an option at this time - other parts of the design require this to be a regex. Gr. Okay, how about that regex callback thingie thing thing, and you can use a function that pretty much does: (strlen($1) 42 !strstr($1, '')) -- 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] Regex help
On 28 Jan 2005 [EMAIL PROTECTED] wrote: Thanks, Tom. I agree, but not an option at this time - other parts of the design require this to be a regex. It is pretty easy to do with two regexps, one to check the length and another to see if there is a double . Would that work? I don't know off hand how to do it with a single regexp. If the design requires that every possible condition be checked with a single regexp then I would say, no offense intended, that the design is faulty. Regexps are good tools but are not universal for all possible conditions one might want to test. -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
[EMAIL PROTECTED] wrote on 01/28/2005 04:13:38 PM: On 28 Jan 2005 [EMAIL PROTECTED] wrote: Thanks, Tom. I agree, but not an option at this time - other parts of the design require this to be a regex. It is pretty easy to do with two regexps, one to check the length and another to see if there is a double . Would that work? I don't know off hand how to do it with a single regexp. If the design requires that every possible condition be checked with a single regexp then I would say, no offense intended, that the design is faulty. Regexps are good tools but are not universal for all possible conditions one might want to test. Thanks Tom and Richard. No offense taken. The design isn't mine, I am plugging in to another system that expects a regex. I think I may have to push back on this one :) Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
Mike Ford wrote: Just off the top of my head (and untested!), I'd try something like /b(\s+[^]*)?/ Cheers! Mike That pretty much seems to work the best. Thanks all! -- Jason Morehouse Vendorama - Create your own online store http://www.vendorama.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
On Thu, 13 Jan 2005 16:06:32 -0500, Jason Morehouse [EMAIL PROTECTED] wrote: Hello, I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. Put in a \b to match a wordbreak after the 'b'. Something like this maybe: /b\b[^]*/i . -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regex help
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -Original Message- From: Jason Morehouse Sent: 13/01/05 21:06 I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. Just off the top of my head (and untested!), I'd try something like /b(\s+[^]*)?/ Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regex help
Do you have the example regex so far? I'd suggest maybe b[^r] might just do what you want -Original Message- From: Jason Morehouse [mailto:[EMAIL PROTECTED] Sent: 13 January 2005 21:07 To: php-general@lists.php.net Subject: [PHP] regex help Hello, I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. Thanks! -- Jason Morehouse Vendorama - Create your own online store http://www.vendorama.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php This message has been checked for all known viruses by the CitC Virus Scanning Service powered by SkyLabs. For further information visit http://www.citc.it ___ This message has been checked for all known viruses by the CitC Virus Scanning Service powered by SkyLabs. For further information visit http://www.citc.it ___ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
On Friday 14 January 2005 05:06, Jason Morehouse wrote: Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. Quick-n-dirty: preg_match_all('/(b|b\s+.*)/iU', $doo, $match); Feel free to extend to check for closing tags :) -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
Jason Morehouse wrote: Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. I think something not unlike: '/b( .*|)/' The point being that you either have JUST '' OR you have a SPACE and whatever and '' I leave the capitalization and 'greedy' settings up to you. The previous solution using 'b[^r]' will work only until the goofball browser wars give us some other bX tag where X is a single character in the alphabet. There's a pretty cool Windows/Linux product a colleague swears by that's called RegexCoach (?) which will not only let you try out expressions/values and tell you which ones pass/fail, but you can highlight sub-sections of the expression/values and see what it matches piece by piece. It's donationware -- try it out and donate the $20 (oooh, hurt me) if you like it. http://www.weitz.de/regex-coach/ -- 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] regex help
On Thu, 2005-01-13 at 15:06, Jason Morehouse wrote: Hello, I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. interesting. I usually try to specifically describe in english what I am looking for. in your case, I would say a string that begins with followed by zero or more spaces followed by a b or a B followed by zero or more spaces followed by zero or more anything followed by /\s*[bB]\s*.*/ or perhaps it is enough to say match a followed by 0 or more spaces followed by a b or a B and not followed by a r or a R and followed by zero or more anything followed by /\s*[bB][^rR].*/ These are untested but should be close and can be used in preg* functions. the greedy matching might grab too much stuff and I always forget how to do that when I hit it. try them, let us see the results and we can get there Bret -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex help
Hello, I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. Thanks! -- Jason Morehouse Vendorama - Create your own online store http://www.vendorama.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
Jason Morehouse wrote: Hello, I normally can take a bit of regex fun, but not this time. Simple enough, in theory... I need to match (count) all of the bold tags in a string, including ones with embedded styles (or whatever else can go in there). b and b style=color:red. My attempts keep matching br as well. okay, you didn't show the regexp you currently have no worries - I happen to have struck the same problem about 9 months ago when I had to screenscrape product info from a static site for importation into a DB, heres a list of regexps which will hopefully give you enough info to do what you want (the fifth regexp is the one you should look at most closely): // strip out top and bottom $str = preg_replace('/[\/]?html/is','',$str); // strip out body tags $str = preg_replace('/[\/]?body[^]*/is','',$str); // strip out head $str = preg_replace('/head.*[\/]head/Uis','',$str); // strip out non product images $str = preg_replace('/img[^]*(nieuw|new|euro)\.gif[^]*\/?/Uis','',$str); // strip out font, div, span, p, b $str = preg_replace('/[\/]?(font|div|span|p|b[^r])[^]*/Uis','',$str); // table, td, tr attributes $str = preg_replace('/(table|td|tr)[^]*/Uis','$1',$str); // strip out the first table and hr? $str = preg_replace('/table.*hr/Uis','',$str, 1); // strip table, td, tr $str = preg_replace('/[\/]?(table|td|tr|h5)/Ui','',$str); // strip out all new lines $str = str_replace(\n, '', $str); // strip out tabs $str = preg_replace('/[\011]+/', ' ', $str); // strip out extra white space $str = preg_replace('/[ ]+/', ' ', $str); Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help...
Hi All, I rather badly need some help with a regular expression. I need to identify the occurrence of the following search string in another string, and replace it with some text followed by the identified search string. search string pa href=http://mysite/index.php?p=2#more-2;(more#8230;)/a/p /search string The consistent part of the string is the text (more#8230;)/a/p Essentially, I'm trying to figure out how to insert text prior to the opening p in this line. Can anyone give me a hand in working this out? Many thanks in advance! Much warmth, Murray
[PHP] regex help and file question
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 = -- - 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!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex help
I am at the tailend of a project that involves moving legacy data from one dbms to another. The client has added a new requirement to the data manipulation that is required. I need to remove all br / tags (there may be more that one) that appear within all h* tags. I am not very familiar with building regular expressions, but I see this as a 2 part process. First, to grab h* tags, and second, to strip the br's. I can grab the beginning of the tag easily, but my expressions grab too much. Also, I am not sure how to remove the br's. Any help would be appreciated. I have tried to find similar examples, but without any luck. Also, php5 is not an option at this point. Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
Can you post a little sample of the data and your current code? thanks. Jim Grill Web-1 Hosting http://www.web-1hosting.net - Original Message - From: Kathleen Ballard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 01, 2004 8:27 AM Subject: [PHP] regex help I am at the tailend of a project that involves moving legacy data from one dbms to another. The client has added a new requirement to the data manipulation that is required. I need to remove all br / tags (there may be more that one) that appear within all h* tags. I am not very familiar with building regular expressions, but I see this as a 2 part process. First, to grab h* tags, and second, to strip the br's. I can grab the beginning of the tag easily, but my expressions grab too much. Also, I am not sure how to remove the br's. Any help would be appreciated. I have tried to find similar examples, but without any luck. Also, php5 is not an option at this point. Kathleen -- 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
[PHP] regex help needed
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
Re: [PHP] regex help
On Sun, 1 Aug 2004 06:27:51 -0700 (PDT), Kathleen Ballard [EMAIL PROTECTED] wrote: I am at the tailend of a project that involves moving legacy data from one dbms to another. The client has added a new requirement to the data manipulation that is required. I need to remove all br / tags (there may be more that one) that appear within all h* tags. I am not very familiar with building regular expressions, but I see this as a 2 part process. First, to grab h* tags, and second, to strip the br's. I can grab the beginning of the tag easily, but my expressions grab too much. Also, I am not sure how to remove the br's. Any help would be appreciated. I have tried to find similar examples, but without any luck. Also, php5 is not an option at this point. $text = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text); You may also have to do this several times as this will only get one br per h tag. $newText = $text; do { $text = $newText; $newText = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text); } while($text != $newText); Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help
Forget my first attempt, using the e modifier and another preg_replace is much better. $return = preg_replace('!h(\d)(.*?)/h\1!ie', 'preg_replace(!br[^]*!i, , $1)', $originalText); On Sun, 1 Aug 2004 13:39:49 -0700, Justin Patrin [EMAIL PROTECTED] wrote: On Sun, 1 Aug 2004 06:27:51 -0700 (PDT), Kathleen Ballard [EMAIL PROTECTED] wrote: I am at the tailend of a project that involves moving legacy data from one dbms to another. The client has added a new requirement to the data manipulation that is required. I need to remove all br / tags (there may be more that one) that appear within all h* tags. I am not very familiar with building regular expressions, but I see this as a 2 part process. First, to grab h* tags, and second, to strip the br's. I can grab the beginning of the tag easily, but my expressions grab too much. Also, I am not sure how to remove the br's. Any help would be appreciated. I have tried to find similar examples, but without any luck. Also, php5 is not an option at this point. $text = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text); You may also have to do this several times as this will only get one br per h tag. $newText = $text; do { $text = $newText; $newText = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text); } while($text != $newText); Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex help needed
On Sun, 1 Aug 2004 10:38:06 -0700 (PDT) Kathleen Ballard [EMAIL PROTECTED] 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 Simple: while (preg_match(/(h\d)(.*)(br \/)(.*)(\/h\d)/is, $str)) { $str = preg_replace(/(h\d)(.*)(br \/)(.*)(\/h\d)/is, $1$2$4$5, $str); } $str = preg_replace(/(h\d)(.*)(\/h\d)/is, $2, $str); Recommended: $str = preg_replace(/(h\d)([^]*)()(.*)(\/h\d)/eis, remove_br('$4'), $str); function remove_br($str){ return preg_replace(/(br)([^]*)()/i, , $str); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex Help
Greetings list, I have been given a list of products, and I need some help building a regular expression to split the category from the sub category. Example: CamerasDigital_CannonXLRshot -Original entry in list Cameras Digital Cannon XLRshot -Desired result. I can use str_replace() for the underscore, but I also want to be able to split on lowercase char followed by an uppercase char. I have not worked with regular expressions much before, and I just need a push in the right direction. Thanks in advance, Keith -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help
* Thus wrote hitek ([EMAIL PROTECTED]): Greetings list, I have been given a list of products, and I need some help building a regular expression to split the category from the sub category. Example: CamerasDigital_CannonXLRshot -Original entry in list Cameras Digital Cannon XLRshot -Desired result. One possiblity: echo preg_replace('/([a-z])_?([A-Z])/', '$1 $2', 'CamerasDigital_CannonXLRshot'); explanation: match a lower case character preceding an uppercase character, with an optional underscore between them. Replace that match with the matched lowercase character, space and matched uppercase character. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex Help
Curt, That's perfect. Works like a charm. Thanks, Keith At 03:54 PM 5/10/2004, Curt Zirzow wrote: * Thus wrote hitek ([EMAIL PROTECTED]): Greetings list, I have been given a list of products, and I need some help building a regular expression to split the category from the sub category. Example: CamerasDigital_CannonXLRshot -Original entry in list Cameras Digital Cannon XLRshot -Desired result. One possiblity: echo preg_replace('/([a-z])_?([A-Z])/', '$1 $2', 'CamerasDigital_CannonXLRshot'); explanation: match a lower case character preceding an uppercase character, with an optional underscore between them. Replace that match with the matched lowercase character, space and matched uppercase character. Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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] Regex help - PLease
Sorry I to should have added this this is what im going with so far preg_match(/\d100.*/); This will match a digit, followed by '100', followed by anything. Go with Rob's suggestion. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help - PLease
Hi there im in desperate need of help for a reg expression to ONLY allow 8 NUMBERS to start with 100 and may not have any other kind of letters or characters. Only numbers for example 10064893 Kind Regards And thank you Brent Clark
[PHP] Regex help - PLease
Sorry I to should have added this this is what im going with so far preg_match(/\d100.*/); Kind Regards Brent Clark
Re: [PHP] Regex help - PLease
Hello Brent, Tuesday, March 16, 2004, 12:39:27 PM, you wrote: BC im in desperate need of help for a reg expression to ONLY allow 8 BC NUMBERS to start with 100 and may not have any other kind of BC letters or characters. Only numbers BC for example BC 10064893 It's not a reg exp, but it will work: if (is_numeric($val) == FALSE || strlen($val) 8 || substr($val, 0, 3) !== 100) { // $val doesn't match } Conversely: if (is_numeric($val) == TRUE strlen($val) == 8 substr($val, 0, 3) == 100) { // $val does match } (Code not tested, but you get the idea I hope) -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help - PLease
On Tue, Mar 16, 2004 at 02:39:27PM +0200, Brent Clark wrote: Hi there im in desperate need of help for a reg expression to ONLY allow 8 NUMBERS to start with 100 and may not have any other kind of letters or characters. Only numbers for example 10064893 if (preg_match('/^100\d{5}/', $test)) print ok\n; - rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help - PLease
On 03/16/2004 6:57 AM, Rob Ellis [EMAIL PROTECTED] wrote: On Tue, Mar 16, 2004 at 02:39:27PM +0200, Brent Clark wrote: Hi there im in desperate need of help for a reg expression to ONLY allow 8 NUMBERS to start with 100 and may not have any other kind of letters or characters. Only numbers for example 10064893 if (preg_match('/^100\d{5}/', $test)) print ok\n; Unless you want to allow something like '10064893A' to match, use: preg_match('/^100\d{5}$/', $test) Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex help
Hi, I know this is pretty easy to do but I am horrorable at working with regular expressions and was wondering if anybody might take a min to help please. I will have a variable: $the_extention which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c eg: Using the above variable I want to do something like $second_extention= use_regex_here($the_extention) (value of $second_extention becomes: 98797-234234) A good baby steps tutorial on regex too would be appreciated. Thanks in advance, Cheers, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
Ryan A mailto:[EMAIL PROTECTED] on Monday, March 15, 2004 9:07 AM said: I know this is pretty easy to do but I am horrorable at working with regular expressions and was wondering if anybody might take a min to help please. in that case you should get the regex coach (easy to find via google). it's great! I will have a variable: $the_extention which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c by using () around the part you want to grab. ?php $string = 98797-234234--2c-something-2c; $pattern = /\d{5}-\d{6}--2c-(.*)-2c/; preg_match($pattern, $string, $matches); print_r($matches); ? A good baby steps tutorial on regex too would be appreciated. there's lots of those. google can help you find them. try regular expression tutorial or some variant of that. hth, chris. p.s. i think you want extension not extention. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On Tuesday 16 March 2004 01:06, Ryan A wrote: I know this is pretty easy to do but I am horrorable at working with regular expressions and was wondering if anybody might take a min to help please. I will have a variable: $the_extention which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c For something as simple and predictable as that using regex seems to be an overkill. The simple string functions ought to be adequate. explode() might be all you need. eg: Using the above variable I want to do something like $second_extention= use_regex_here($the_extention) (value of $second_extention becomes: 98797-234234) A good baby steps tutorial on regex too would be appreciated. google -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* When I left you, I was but the pupil. Now, I am the master. - Darth Vader */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
I will have a variable: $the_extention which will have a value like: 98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c You could use preg_replaces, like so: $result = preg_replace('/--2c.+-c/', '', $the_extention); That matches anything between '--2c' and '-2c' and replaces it with ''. You could also use preg_match, like so: preg_match('/^(.+)--2c.+-c$/', $the_extention, $matches); $matches[1] should contain the substring you need. A good baby steps tutorial on regex too would be appreciated. Chapter 7 of Learning Perl is an excellent tutorial and basic reference. http://www.oreilly.com/catalog/lperl3/ As usual, the trusty PHP manual also has good information: http://www.php.net/manual/en/pcre.pattern.syntax.php - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
At 6:06 PM +0100 3/15/04, Ryan A wrote: I know this is pretty easy to do but I am horrorable at working with regular expressions and was wondering if anybody might take a min to help please. I will have a variable: $the_extention which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c I'd be interested in the answer to this question as well. Seems like it should be easy. A good baby steps tutorial on regex too would be appreciated. This is a good one: http://www.regular-expressions.info/tutorial.html This google search turned up many tutorials: http://tinyurl.com/2r3rf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regex help
Hey, Thanks guys. I did search on google first for a tutorial, problem is with something as widely used as regular expressions there are LOTS of results...I felt it would be better to ask if anyone has a favourite.. ie: if you learnt it off the web and not via the manual. The last time I had this problem was with cookies and sessions, I found the links I got from the people on this list much better than the examples in the manual...after learning from the web I did go back to the manual and understood thing much better. Cheers, -Ryan On 3/15/2004 6:18:38 PM, Chris W. Parker ([EMAIL PROTECTED]) wrote: Ryan A mailto:[EMAIL PROTECTED] on Monday, March 15, 2004 9:07 AM said: I know this is pretty easy to do but I am horrorable at working with regular expressions and was wondering if anybody might take a min to help please. in that case you should get the regex coach (easy to find via google). it's great! I will have a variable: $the_extention which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c by using () around the part you want to grab. ?php $string = 98797-234234--2c-something-2c; $pattern = /\d{5}-\d{6}--2c-(.*)-2c/; preg_match($pattern, $string, $matches); print_r($matches); ? A good baby steps tutorial on regex too would be appreciated. there's lots of those. google can help you find them. try regular expression tutorial or some variant of that. hth, chris. p.s. i think you want extension not extention. :) -- PHP General Mailing List (http://www.php.net/) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help
On 15 Mar 2004 Eric Gorr wrote: which will have a value like:98797-234234--2c-something-2c How do I take out the part which will always start with --2c and will always end with -2c I'd be interested in the answer to this question as well. Seems like it should be easy. It is easy. I agree with whoever said string functions were a better solution, regexp is overkill unless there is more variaiton in the data than what was presented. That said, here are some possibilities; all but the first assume that the -- is always there: - If the lengths are constant just use substr to pull out the first 11 characters. - Find the -- with strpos and then use that in a substr call to take just the part to the left. - Use explode to separate the string at the -- or --2c. - For two numeric strings separated by a dash use a regexp approach something like this: if (preg_match(/^(\d*-\d*)--2c/, $string, $matches)) $left_part = $matches[1]; -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex help (SOLVED)
Hey Guys, Solved this, took your advise and avoided regex as its an overkill. Case you're interested: $th_var=98797-234234--2c-something-2c; $piece = explode(--2, $th_var); echo $piece[0]; (and if i want to use the second part... $piece[1] ) Thanks to everyone who gave me examples, links and suggested alternatives like explode(), but personally I thought explode too was a regex..:-(. Cheers, -Ryan A -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php