[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 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 - 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 please
I have tried numerous variations, but my regex skills suck! I would appreciate anyone who can give me a pattern to use in preg_match_all() to match the following (I have the first part up to ANYTHING working): '|function ([\w\d\_]+)\((.*)\)ANYTHINGreturn (ANYTHING);|' So parsing a PHP file I hope to have 3 backreferences that return the function name, function args and return value (if present) of all functions. Thanks! -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php