Re: [PHP] Regular expressions, filter option1 OR option2

2010-08-18 Thread Shreyas Agasthya
Camilo,

What exactly are you trying to achieve? Meaning:

if (true)
   do this;
if (false)
   do that;

However, here's a link that I used long back to help me with some RegEx :
http://www.gskinner.com/RegExr/

Regards,
Shreyas

On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg csperb...@unreal4u.comwrote:

 Hello list :)

 Just a short question which I know it should be easy, but I'm no expert yet
 in regular expressions.
 I've got a nice little XML string, which is something like this but can be
 changed:

 ?xml version=1.0 encoding=utf-8?
 boolean xmlns=http://tempuri.org/;false/boolean

 The boolean value can be true or false, so what I want to do, is filter it.
 I've done it this way, but I know it can be improved (just because I love
 clean coding and also because I want to master regular expressions xD):

  $result = preg_match('/true/',$curl_response);
  if ($result == 0) $result = preg_match('/false/',$curl_response);

 I've also tried something like:
 $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
 true OR not false = replace with empty

 and also '/^true|^false/' which doesn't seem to work.

 Any ideas to filter this kind of string in just one expression?

 Thanks in advance :)

 --
 Mailed by:
 UnReAl4U - unreal4u
 ICQ #: 54472056
 www1: http://www.chw.net/
 www2: http://unreal4u.com/




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Regular expressions, filter option1 OR option2

2010-08-18 Thread Ashley Sheridan
On Wed, 2010-08-18 at 23:36 +0530, Shreyas Agasthya wrote:

 Camilo,
 
 What exactly are you trying to achieve? Meaning:
 
 if (true)
do this;
 if (false)
do that;
 
 However, here's a link that I used long back to help me with some RegEx :
 http://www.gskinner.com/RegExr/
 
 Regards,
 Shreyas
 
 On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg 
 csperb...@unreal4u.comwrote:
 
  Hello list :)
 
  Just a short question which I know it should be easy, but I'm no expert yet
  in regular expressions.
  I've got a nice little XML string, which is something like this but can be
  changed:
 
  ?xml version=1.0 encoding=utf-8?
  boolean xmlns=http://tempuri.org/;false/boolean
 
  The boolean value can be true or false, so what I want to do, is filter it.
  I've done it this way, but I know it can be improved (just because I love
  clean coding and also because I want to master regular expressions xD):
 
   $result = preg_match('/true/',$curl_response);
   if ($result == 0) $result = preg_match('/false/',$curl_response);
 
  I've also tried something like:
  $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
  true OR not false = replace with empty
 
  and also '/^true|^false/' which doesn't seem to work.
 
  Any ideas to filter this kind of string in just one expression?
 
  Thanks in advance :)
 
  --
  Mailed by:
  UnReAl4U - unreal4u
  ICQ #: 54472056
  www1: http://www.chw.net/
  www2: http://unreal4u.com/
 
 
 
 


As far as I can tell, are you just trying to grab the content from the
boolean tag text node? If it's limited to this basic example, there's
likely not much of a need to use dedicated DOM functions, but consider
using them if you need to work on more complex documents.

If you are just trying to determine if the value is indeed true or false
and nothing else, then a regex could be overkill here. As you only need
to check two values, consider:

if(strpos($xml, 'true') || strpos($xml, 'false'))
{
// text node content is OK
}
else
{
// bad, bad input, go sit in the corner
}

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Regular expressions, filter option1 OR option2

2010-08-18 Thread Camilo Sperberg
On Wed, Aug 18, 2010 at 15:01, Ashley Sheridan a...@ashleysheridan.co.ukwrote:

  On Wed, 2010-08-18 at 23:36 +0530, Shreyas Agasthya wrote:

 Camilo,

 What exactly are you trying to achieve? Meaning:

 if (true)
do this;
 if (false)
do that;

 However, here's a link that I used long back to help me with some RegEx 
 :http://www.gskinner.com/RegExr/

 Regards,
 Shreyas

 On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg 
 csperb...@unreal4u.comwrote:

  Hello list :)
 
  Just a short question which I know it should be easy, but I'm no expert yet
  in regular expressions.
  I've got a nice little XML string, which is something like this but can be
  changed:
 
  ?xml version=1.0 encoding=utf-8?
  boolean xmlns=http://tempuri.org/;false/boolean
 
  The boolean value can be true or false, so what I want to do, is filter it.
  I've done it this way, but I know it can be improved (just because I love
  clean coding and also because I want to master regular expressions xD):
 
   $result = preg_match('/true/',$curl_response);
   if ($result == 0) $result = preg_match('/false/',$curl_response);
 
  I've also tried something like:
  $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
  true OR not false = replace with empty
 
  and also '/^true|^false/' which doesn't seem to work.
 
  Any ideas to filter this kind of string in just one expression?
 
  Thanks in advance :)
 
  --
  Mailed by:
  UnReAl4U - unreal4u
  ICQ #: 54472056
  www1: http://www.chw.net/
  www2: http://unreal4u.com/
 





 As far as I can tell, are you just trying to grab the content from the
 boolean tag text node? If it's limited to this basic example, there's
 likely not much of a need to use dedicated DOM functions, but consider using
 them if you need to work on more complex documents.

 If you are just trying to determine if the value is indeed true or false
 and nothing else, then a regex could be overkill here. As you only need to
 check two values, consider:

 if(strpos($xml, 'true') || strpos($xml, 'false'))
 {
 // text node content is OK
 }
 else
 {
 // bad, bad input, go sit in the corner
 }


Indeed Ashley, I'm trying to get the TRUE / FALSE value from the boolean
tag.

After reading again, you're absolutely right: strpos does just what I need
it to do: a simple search for a true or false. (Or null, in which case
strpos will be FALSE anyway).

Thanks for your suggestion, I was doing an overkill here.

@Shreyas: thanks for the link! It is very helpful to speed up the testing a
bit!

Greetings!


-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Regular expressions (regex) question for parsing

2008-12-22 Thread Daniel Brown
On Mon, Dec 22, 2008 at 15:56, Rene Fournier renefourn...@gmail.com wrote:

 Each line should start with a $dollar sign, then some arbitrary text, ends
 with a percent sign, followed by carriage-return and line-feed. Sometimes
 though, the final line is not complete. In that case, I want to save those
 lines too.

Just a quick note on that, Rene

 $result = array (   matches =
array ( 0 = $sometext %\r\n,

If you want to have the dollar sign included, use single quotes.
Double-quoted things translate the data enclosed within them, so
$sometext would translate that into the value of the variable (or
null with E_NOTICE if it's uninstantiated/undefined).  Conversely,
'$sometext' would be the literal $sometext.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions (regex) question for parsing

2008-12-22 Thread Jim Lucas
Rene Fournier wrote:
 Hi, I'm looking for some ideas on the best way to parse blocks of text
 that is formatted such as:
 
 $sometext %\r\n-- good data   
 $otherstring %\r\n-- good data
 $andyetmoretext %\r\n-- good data
 $finaltext -- bad data (missing ending)
 
 Each line should start with a $dollar sign, then some arbitrary text,
 ends with a percent sign, followed by carriage-return and line-feed.
 Sometimes though, the final line is not complete. In that case, I want
 to save those lines too.
 
 so that I end up with an array like:
 
 $result = array (matches =
 array (0 = $sometext %\r\n,
 1 = $otherstring %\r\n,
 2 = $andyetmoretext %\r\n
 ),
 non_matches =
 array (3 = $finaltext
 )
 );
 
 The key thing here is that the line numbers are preserved and the
 non-matched lines are saved...
 
 Any ideas, what's the best way to go about this? Preg_matc, preg_split
 or something incorporating explode?
 
 Rene
 

Something along the line of this?

pre?php

$block_of_text = '$sometext %\r\n
$otherstring %\r\n
$andyetmoretext %\r\n
$finaltext';

$lines = explode(\n, $block_of_text);

$results = array();

foreach ( $lines AS $i = $line ) {
if ( preg_match('|^\$.* %\\\r\\\n$|', $line ) ) {
$results['matches'][$i] = $line;
} else {
$results['non_matches'][$i] = $line;
}
}

print_r($results);

?


-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions (regex) question for parsing

2008-12-22 Thread Lars Torben Wilson
2008/12/22 Jim Lucas li...@cmsws.com:
 Rene Fournier wrote:
 Hi, I'm looking for some ideas on the best way to parse blocks of text
 that is formatted such as:

 $sometext %\r\n-- good data
 $otherstring %\r\n-- good data
 $andyetmoretext %\r\n-- good data
 $finaltext -- bad data (missing ending)

 Each line should start with a $dollar sign, then some arbitrary text,
 ends with a percent sign, followed by carriage-return and line-feed.
 Sometimes though, the final line is not complete. In that case, I want
 to save those lines too.

 so that I end up with an array like:

 $result = array (matches =
 array (0 = $sometext %\r\n,
 1 = $otherstring %\r\n,
 2 = $andyetmoretext %\r\n
 ),
 non_matches =
 array (3 = $finaltext
 )
 );

 The key thing here is that the line numbers are preserved and the
 non-matched lines are saved...

 Any ideas, what's the best way to go about this? Preg_matc, preg_split
 or something incorporating explode?

 Rene


 Something along the line of this?

 pre?php

 $block_of_text = '$sometext %\r\n
 $otherstring %\r\n
 $andyetmoretext %\r\n
 $finaltext';

 $lines = explode(\n, $block_of_text);

 $results = array();

 foreach ( $lines AS $i = $line ) {
if ( preg_match('|^\$.* %\\\r\\\n$|', $line ) ) {
$results['matches'][$i] = $line;
} else {
$results['non_matches'][$i] = $line;
}
 }

 print_r($results);

 ?

I know I'm arguing against premature optimization in another thread at
the moment, but using regexps for this is overkill from the get-go:

if ($line[0] === '$'  substr($line, -3) === %\r\n) {

This is both faster and easier to read. Regexps are great for more
complex stuff but something this simple doesn't demand their power (or
overhead).


Torben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-07 Thread Richard Lynch
The + requires at least one character.

The * is 0 or more characters.

http://php.net/pcre

On Wed, March 5, 2008 9:13 am, It Maq wrote:
 Hi,

 I am using that right now and i have don't know how to include blank
 fields. For example if a user does not fill a field in a form i want
 to accept it. I tried the code you posted, for now it is blocking
 blank fields.

 Thank you

 - Original Message 
 From: Richard Lynch [EMAIL PROTECTED]
 To: Adil Drissi [EMAIL PROTECTED]
 Cc: php-general@lists.php.net
 Sent: Tuesday, March 4, 2008 3:09:09 PM
 Subject: Re: [PHP] regular expressions question

 On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
 Is there any way to limit the user to a set of characters for
 example
 say i want my user to enter any character between a and z (case
 insensitive). And if the user enters just one letter not belonging
 to
 [a-z], this will not be accepted.

 I tried  eregi('[a-z]', $fname) but this allows the user to enter
 abdg4512kdkdk for example.

 What you tried only requires ONE a-z character somewhere in the input.

 Try this:

 preg_match('^[a-z]+$', $fname);

 This will:
 ^ anchor the string at the beginning
 [a-z]+ a to z, with at least one letter
 $ anchor the string at the end

 Note, however, that some people have other characters in their first
 name, such as apostrophe, space, and dash.

 Oh, and the digit 3, for bo3b who was a programmer on the first
 Apple Macintosh.  His parents were hippies, and that really is his
 name...

 You may want to obtain a LARGE list of first names and run them
 through your validator as a test.

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/from/lynch
 Yeah, I get a buck. So?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php







   
 
 Never miss a thing.  Make Yahoo your home page.
 http://www.yahoo.com/r/hs


-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-05 Thread It Maq
Hi,

I am using that right now and i have don't know how to include blank fields. 
For example if a user does not fill a field in a form i want to accept it. I 
tried the code you posted, for now it is blocking blank fields.

Thank you

- Original Message 
From: Richard Lynch [EMAIL PROTECTED]
To: Adil Drissi [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Tuesday, March 4, 2008 3:09:09 PM
Subject: Re: [PHP] regular expressions question

On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
 Is there any way to limit the user to a set of characters for example
 say i want my user to enter any character between a and z (case
 insensitive). And if the user enters just one letter not belonging to
 [a-z], this will not be accepted.

 I tried  eregi('[a-z]', $fname) but this allows the user to enter
 abdg4512kdkdk for example.

What you tried only requires ONE a-z character somewhere in the input.

Try this:

preg_match('^[a-z]+$', $fname);

This will:
^ anchor the string at the beginning
[a-z]+ a to z, with at least one letter
$ anchor the string at the end

Note, however, that some people have other characters in their first
name, such as apostrophe, space, and dash.

Oh, and the digit 3, for bo3b who was a programmer on the first
Apple Macintosh.  His parents were hippies, and that really is his
name...

You may want to obtain a LARGE list of first names and run them
through your validator as a test.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php







  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Re: [PHP] regular expressions question

2008-03-05 Thread Robert Cummings

On Wed, 2008-03-05 at 07:13 -0800, It Maq wrote:
 Hi,
 
 I am using that right now and i have don't know how to include blank fields. 
 For example if a user does not fill a field in a form i want to accept it. I 
 tried the code you posted, for now it is blocking blank fields.
 
 Thank you
 
 - Original Message 
 From: Richard Lynch [EMAIL PROTECTED]
 To: Adil Drissi [EMAIL PROTECTED]
 Cc: php-general@lists.php.net
 Sent: Tuesday, March 4, 2008 3:09:09 PM
 Subject: Re: [PHP] regular expressions question
 
 On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
  Is there any way to limit the user to a set of characters for example
  say i want my user to enter any character between a and z (case
  insensitive). And if the user enters just one letter not belonging to
  [a-z], this will not be accepted.
 
  I tried  eregi('[a-z]', $fname) but this allows the user to enter
  abdg4512kdkdk for example.
 
 What you tried only requires ONE a-z character somewhere in the input.
 
 Try this:
 
 preg_match('^[a-z]+$', $fname);

preg_match('^[a-z]*$', $fname);

Someone else posted this also, but you may have missed it.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-04 Thread David Giragosian
On 3/4/08, Adil Drissi [EMAIL PROTECTED] wrote:
 Hi,

 Is there any way to limit the user to a set of characters for example say i 
 want my user to enter any character between a and z (case insensitive). And 
 if the user enters just one letter not belonging to [a-z], this will not be 
 accepted.

 I tried  eregi('[a-z]', $fname) but this allows the user to enter 
 abdg4512kdkdk for example.

 Thank you


try here:

http://us2.php.net/ctype_alpha

-- 

-David.

When the power of love
overcomes the love of power,
the world will know peace.

-Jimi Hendrix

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-04 Thread Daniel Brown
On Tue, Mar 4, 2008 at 2:19 PM, Adil Drissi [EMAIL PROTECTED] wrote:
 Hi,

  Is there any way to limit the user to a set of characters for example say i 
 want my user to enter any character between a and z (case insensitive). And 
 if the user enters just one letter not belonging to [a-z], this will not be 
 accepted.

?
if(preg_match('/^[a-z]+$/i',$argv[1])) {
echo Good.\n;
} else {
echo Bad.\n;
}
?

-- 
/Dan

Daniel P. Brown
Senior Unix Geek
? while(1) { $me = $mind--; sleep(86400); } ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-04 Thread Richard Lynch
On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
 Is there any way to limit the user to a set of characters for example
 say i want my user to enter any character between a and z (case
 insensitive). And if the user enters just one letter not belonging to
 [a-z], this will not be accepted.

 I tried  eregi('[a-z]', $fname) but this allows the user to enter
 abdg4512kdkdk for example.

What you tried only requires ONE a-z character somewhere in the input.

Try this:

preg_match('^[a-z]+$', $fname);

This will:
^ anchor the string at the beginning
[a-z]+ a to z, with at least one letter
$ anchor the string at the end

Note, however, that some people have other characters in their first
name, such as apostrophe, space, and dash.

Oh, and the digit 3, for bo3b who was a programmer on the first
Apple Macintosh.  His parents were hippies, and that really is his
name...

You may want to obtain a LARGE list of first names and run them
through your validator as a test.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions question

2008-03-04 Thread Adil Drissi
Thank you guys,

The answers you gave me not only solved the problem,
but i included more characters like space and -.

Thank you again

--- Richard Lynch [EMAIL PROTECTED] wrote:

 On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
  Is there any way to limit the user to a set of
 characters for example
  say i want my user to enter any character between
 a and z (case
  insensitive). And if the user enters just one
 letter not belonging to
  [a-z], this will not be accepted.
 
  I tried  eregi('[a-z]', $fname) but this allows
 the user to enter
  abdg4512kdkdk for example.
 
 What you tried only requires ONE a-z character
 somewhere in the input.
 
 Try this:
 
 preg_match('^[a-z]+$', $fname);
 
 This will:
 ^ anchor the string at the beginning
 [a-z]+ a to z, with at least one letter
 $ anchor the string at the end
 
 Note, however, that some people have other
 characters in their first
 name, such as apostrophe, space, and dash.
 
 Oh, and the digit 3, for bo3b who was a programmer
 on the first
 Apple Macintosh.  His parents were hippies, and that
 really is his
 name...
 
 You may want to obtain a LARGE list of first names
 and run them
 through your validator as a test.
 
 -- 
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/from/lynch
 Yeah, I get a buck. So?
 
 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2007-12-12 Thread tedd

At 2:04 AM -0500 12/12/07, Robert Cummings wrote:

?php

if( strlen( $pw1 )  6
||
!ereg( '[[:digit:]]', $pw1 )
||
strlen( ereg_replace( '[^[:alpha:]]', '', $pw1 ) )  2
||
strlen( ereg_replace( '[[:alnum:][:space:]]', '', $pw1 ) )  1 )
{
// error message
}

?

Cheers,
Rob.


Rob:

You are a never ending supply for great snip-its!

Thanks,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2007-12-11 Thread Robert Cummings
On Tue, 2007-12-11 at 22:33 -0800, Liz Kim wrote:
 I am trying to do a password match with php..
 
 It needs to be at least 6 characters, contains 2 alphabets and at least 1
 number or a special character...
 
 if
 (!preg_match(/^.*(?=.{6,})((?=.*\d)|(?=.*[,[EMAIL 
 PROTECTED]\/'+\*\?\.\[\]\^$\(\){}\|\\:;'~`#%_-]))([a-zA-Z]{2,}).*$/,
 $pw1)) {error message}
 
 is failing to pass e1w2qw as a good password although it follows the
 instructions...
 
 I cannot figure out why..

Any reason you took such a complex route?

?php

if( strlen( $pw1 )  6
||
!ereg( '[[:digit:]]', $pw1 )
||
strlen( ereg_replace( '[^[:alpha:]]', '', $pw1 ) )  2
||
strlen( ereg_replace( '[[:alnum:][:space:]]', '', $pw1 ) )  1 )
{
// error message
}

?

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
There was no escaping in the original either.

Also, I did assume that the list of replacements would grow to become
pretty large.  I wouldn't suggest doing this for a small list such as
that given in the example.

Robert Cummings wrote:
 On Wed, 2007-11-07 at 14:33 +, Mark Summers wrote:
   
 This is a first attempt but the general idea is that the regular
 expression matching is done in one operation and then str_replace() is
 called only as many times as required instead of once for every line in
 your list.  Also, str_replace() is faster than ereg_replace().

 ?php

 $replace = array(
 ntilde = n,
 aacute = a,
 eacute = e,
 iacute = i,
 oacute = o,
 uacute = u
 );

 $link = ssrsrsrsoacuteererrereiacutesddoacutesdssuacute;

 if (preg_match_all(/(.join(|, array_keys($replace)).)/, $link,
 $matches)) {
 $matches = array_unique($matches);

 foreach ($matches[0] as $match) {
 $link = str_replace($match, $replace[$match], $link);
 }
 }

 echo $link;

 ?
 

 Don't do this, it's terribly inefficient and superfluously complicated.
 There's no escaping of the strings either before jamming them into the
 pattern. What happens if you need to replace ''.

 Cheers,
 Rob.
   


Re: [PHP] Regular Expressions

2007-11-07 Thread Robert Cummings
On Wed, 2007-11-07 at 14:53 +, Mark Summers wrote:
 There was no escaping in the original either.
 
 Also, I did assume that the list of replacements would grow to become
 pretty large.  I wouldn't suggest doing this for a small list such as
 that given in the example.

Given that you expect it to grow then you should have accounted for
special characters becoming part of the list. Additionally, you probably
think this technique is more efficient since you think that the regex
scans the list faster, it does not. If there is nothing to replace the
str_replace() call will be faster than the preg_match_all() call since
it isn't burdened with the overhead of regex special characters and
matching. Additionally, in the event of something actually needing
replaced, you will incur a second scan of the target string since
preg_match_all() doesn't perform the replacement as soon as it realizes
a match is necessary while still having the index of the replacement
spot available. In the event that nothing is replaced you can be assured
that str_replace() returns a virtual copy of the target string, in which
case no duplication overhead is incurred, only the effort to create a
COW version of the variable. This is about as fast as the creation of
the return value of preg_match_all().

Cheers,
Rob.

 
 Robert Cummings wrote:
  On Wed, 2007-11-07 at 14:33 +, Mark Summers wrote:

  This is a first attempt but the general idea is that the regular
  expression matching is done in one operation and then str_replace() is
  called only as many times as required instead of once for every line in
  your list.  Also, str_replace() is faster than ereg_replace().
 
  ?php
 
  $replace = array(
  ntilde = n,
  aacute = a,
  eacute = e,
  iacute = i,
  oacute = o,
  uacute = u
  );
 
  $link = ssrsrsrsoacuteererrereiacutesddoacutesdssuacute;
 
  if (preg_match_all(/(.join(|, array_keys($replace)).)/, $link,
  $matches)) {
  $matches = array_unique($matches);
 
  foreach ($matches[0] as $match) {
  $link = str_replace($match, $replace[$match], $link);
  }
  }
 
  echo $link;
 
  ?
  
 
  Don't do this, it's terribly inefficient and superfluously complicated.
  There's no escaping of the strings either before jamming them into the
  pattern. What happens if you need to replace ''.
 
  Cheers,
  Rob.

-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
This is a much better solution.  I didn't realise that str_replace()
accepted arrays as arguments for the search and replace terms.

Mental note:  reading mailing lists backwards doesn't work.

Robert Cummings wrote:
 On Tue, 2007-11-06 at 23:24 -0300, Martin Alterisio wrote:
   
 2007/11/6, Alberto García Gómez [EMAIL PROTECTED]:
 
 I'm a mess in regular expressions and I make this code:

 $link = ereg_replace('ntilde;','n',$link);
 $link = ereg_replace('aacute;','a',$link);
 $link = ereg_replace('eacute;','e',$link);
 $link = ereg_replace('iacute;','i',$link);
 $link = ereg_replace('oacute;','o',$link);
 $link = ereg_replace('uacute;','u',$link);

 I ask if is a way to make those lines into a single one but working as
 well as this piece. I'm thinking in increase those lines so will be
 wonderful if I can optimize the code.
   

 ?php

 $map = array
 (
 'ntilde;', 'n',
 'aacute;', 'a',
 'eacute;', 'e',
 'iacute;', 'i',
 'oacute;', 'o',
 'uacute;', 'u',
 );

 $link =
 str_replace(
 array_keys( $map ), array_values( $map ), $link );

 ?

 The only way to make it faster is to build the key array and value array
 separately, but then the association is not so clear.

 Cheers,
 Rob.
   


Re: [PHP] Regular Expressions

2007-11-07 Thread Robert Cummings
On Wed, 2007-11-07 at 14:33 +, Mark Summers wrote:
 This is a first attempt but the general idea is that the regular
 expression matching is done in one operation and then str_replace() is
 called only as many times as required instead of once for every line in
 your list.  Also, str_replace() is faster than ereg_replace().
 
 ?php
 
 $replace = array(
 ntilde = n,
 aacute = a,
 eacute = e,
 iacute = i,
 oacute = o,
 uacute = u
 );
 
 $link = ssrsrsrsoacuteererrereiacutesddoacutesdssuacute;
 
 if (preg_match_all(/(.join(|, array_keys($replace)).)/, $link,
 $matches)) {
 $matches = array_unique($matches);
 
 foreach ($matches[0] as $match) {
 $link = str_replace($match, $replace[$match], $link);
 }
 }
 
 echo $link;
 
 ?

Don't do this, it's terribly inefficient and superfluously complicated.
There's no escaping of the strings either before jamming them into the
pattern. What happens if you need to replace ''.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-07 Thread Mark Summers
This is a first attempt but the general idea is that the regular
expression matching is done in one operation and then str_replace() is
called only as many times as required instead of once for every line in
your list.  Also, str_replace() is faster than ereg_replace().

?php

$replace = array(
ntilde = n,
aacute = a,
eacute = e,
iacute = i,
oacute = o,
uacute = u
);

$link = ssrsrsrsoacuteererrereiacutesddoacutesdssuacute;

if (preg_match_all(/(.join(|, array_keys($replace)).)/, $link,
$matches)) {
$matches = array_unique($matches);

foreach ($matches[0] as $match) {
$link = str_replace($match, $replace[$match], $link);
}
}

echo $link;

?

Alberto García Gómez wrote:
 I'm a mess in regular expressions and I make this code:

 $link = ereg_replace('ntilde;','n',$link); 
 $link = ereg_replace('aacute;','a',$link);
 $link = ereg_replace('eacute;','e',$link); 
 $link = ereg_replace('iacute;','i',$link);
 $link = ereg_replace('oacute;','o',$link); 
 $link = ereg_replace('uacute;','u',$link);

 I ask if is a way to make those lines into a single one but working as well 
 as this piece. I'm thinking in increase those lines so will be wonderful if I 
 can optimize the code.



 Este correo ha sido enviado desde el Politécnico de Informática Carlos Marx 
 de Matanzas.
 La gran batalla se librará en el campo de las ideas

   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Ezequiel Gutesman
Maybe this helps

?php


 $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'switch($matches[0]){
case \'aacute;\': return \'a\';
case \'eacute;\': return \'e\';
case \'iacute;\': return \'i\';
case \'oacute;\': return \'o\';
case \'uacute;\': return \'u\';
case \'ntilde;\': return \'n\';
}'
),
$line
);

echo $line;
?

if you want to use this functionality several times:

?php

function myReplace($chr)
{
switch($chr[0]){
case 'aacute;': return 'a';
case 'eacute;': return 'e';
case 'iacute;': return 'i';
case 'oacute;': return 'o';
case 'uacute;': return 'u';
case 'ntilde;': return 'n';
}
}


$line = Hola que tal con aacute; con acento y entilde;e ;

 $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
'myReplace',
$line
);
echo $line;
?

hope this helps. Note that these are pcre (Perl Compatible RegEx).



Alberto García Gómez wrote:
 I'm a mess in regular expressions and I make this code:
 
 $link = ereg_replace('ntilde;','n',$link); 
 $link = ereg_replace('aacute;','a',$link);
 $link = ereg_replace('eacute;','e',$link); 
 $link = ereg_replace('iacute;','i',$link);
 $link = ereg_replace('oacute;','o',$link); 
 $link = ereg_replace('uacute;','u',$link);
 
 I ask if is a way to make those lines into a single one but working as well 
 as this piece. I'm thinking in increase those lines so will be wonderful if I 
 can optimize the code.
 
 
 
 Este correo ha sido enviado desde el Politécnico de Informática Carlos Marx 
 de Matanzas.
 La gran batalla se librará en el campo de las ideas
 

-- 
Ezequiel Gutesman
Researcher
Corelabs
Core Security Technologies
http://www.coresecurity.com/corelabs

PGP Figerprint: 01E4 0E4F 83F8 2D5D 8050 0449 7156 1DF6 C2B3 34AE

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Thiago Ferreira
you could do it without any function
?php

$line = Hola que tal con aacute; con acento y entilde;e \n;

echo preg_replace('/([aeioun])(acute|tilde);/i','\1',$line);

?

On Nov 6, 2007 2:44 PM, Ezequiel Gutesman [EMAIL PROTECTED]
wrote:

 Maybe this helps

 ?php


  $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'switch($matches[0]){
case \'aacute;\': return \'a\';
case \'eacute;\': return \'e\';
case \'iacute;\': return \'i\';
case \'oacute;\': return \'o\';
case \'uacute;\': return \'u\';
case \'ntilde;\': return \'n\';
}'
),
$line
);

 echo $line;
 ?

 if you want to use this functionality several times:

 ?php

 function myReplace($chr)
 {
switch($chr[0]){
case 'aacute;': return 'a';
case 'eacute;': return 'e';
case 'iacute;': return 'i';
case 'oacute;': return 'o';
case 'uacute;': return 'u';
case 'ntilde;': return 'n';
}
 }


 $line = Hola que tal con aacute; con acento y entilde;e ;

  $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
'myReplace',
$line
);
 echo $line;
 ?

 hope this helps. Note that these are pcre (Perl Compatible RegEx).



 Alberto García Gómez wrote:
  I'm a mess in regular expressions and I make this code:
 
  $link = ereg_replace('ntilde;','n',$link);
  $link = ereg_replace('aacute;','a',$link);
  $link = ereg_replace('eacute;','e',$link);
  $link = ereg_replace('iacute;','i',$link);
  $link = ereg_replace('oacute;','o',$link);
  $link = ereg_replace('uacute;','u',$link);
 
  I ask if is a way to make those lines into a single one but working as
 well as this piece. I'm thinking in increase those lines so will be
 wonderful if I can optimize the code.
 
 
 
  Este correo ha sido enviado desde el Politécnico de Informática Carlos
 Marx de Matanzas.
  La gran batalla se librará en el campo de las ideas
 

 --
 Ezequiel Gutesman
 Researcher
 Corelabs
 Core Security Technologies
 http://www.coresecurity.com/corelabs

 PGP Figerprint: 01E4 0E4F 83F8 2D5D 8050 0449 7156 1DF6 C2B3 34AE

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regular Expressions

2007-11-06 Thread Ezequiel Gutesman
True, but you'll have to change the rexex not to match, 'nacute;' or
'atilde; for example (unless you want it)

Thiago Ferreira wrote:
 you could do it without any function
 ?php
 
 $line = Hola que tal con aacute; con acento y entilde;e \n;
 
 echo preg_replace('/([aeioun])(acute|tilde);/i','\1',$line);
 
 ?
 
 On Nov 6, 2007 2:44 PM, Ezequiel Gutesman [EMAIL PROTECTED]
 wrote:
 
 Maybe this helps

 ?php


  $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'switch($matches[0]){
case \'aacute;\': return \'a\';
case \'eacute;\': return \'e\';
case \'iacute;\': return \'i\';
case \'oacute;\': return \'o\';
case \'uacute;\': return \'u\';
case \'ntilde;\': return \'n\';
}'
),
$line
);

 echo $line;
 ?

 if you want to use this functionality several times:

 ?php

 function myReplace($chr)
 {
switch($chr[0]){
case 'aacute;': return 'a';
case 'eacute;': return 'e';
case 'iacute;': return 'i';
case 'oacute;': return 'o';
case 'uacute;': return 'u';
case 'ntilde;': return 'n';
}
 }


 $line = Hola que tal con aacute; con acento y entilde;e ;

  $line = preg_replace_callback(
'/(aacute;|eacute;|iacute;|oacute;|uacute;|ntilde;)/',
'myReplace',
$line
);
 echo $line;
 ?

 hope this helps. Note that these are pcre (Perl Compatible RegEx).



 Alberto García Gómez wrote:
 I'm a mess in regular expressions and I make this code:

 $link = ereg_replace('ntilde;','n',$link);
 $link = ereg_replace('aacute;','a',$link);
 $link = ereg_replace('eacute;','e',$link);
 $link = ereg_replace('iacute;','i',$link);
 $link = ereg_replace('oacute;','o',$link);
 $link = ereg_replace('uacute;','u',$link);

 I ask if is a way to make those lines into a single one but working as
 well as this piece. I'm thinking in increase those lines so will be
 wonderful if I can optimize the code.


 Este correo ha sido enviado desde el Politécnico de Informática Carlos
 Marx de Matanzas.
 La gran batalla se librará en el campo de las ideas

 --
 Ezequiel Gutesman
 Researcher
 Corelabs
 Core Security Technologies
 http://www.coresecurity.com/corelabs

 PGP Figerprint: 01E4 0E4F 83F8 2D5D 8050 0449 7156 1DF6 C2B3 34AE

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 

-- 
Ezequiel Gutesman
Researcher
Corelabs
Core Security Technologies
http://www.coresecurity.com/corelabs

PGP Figerprint: 01E4 0E4F 83F8 2D5D 8050 0449 7156 1DF6 C2B3 34AE

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Jim Lucas

Alberto García Gómez wrote:

I'm a mess in regular expressions and I make this code:

$link = ereg_replace('ntilde;','n',$link); 
$link = ereg_replace('aacute;','a',$link);
$link = ereg_replace('eacute;','e',$link); 
$link = ereg_replace('iacute;','i',$link);
$link = ereg_replace('oacute;','o',$link); 
$link = ereg_replace('uacute;','u',$link);


I ask if is a way to make those lines into a single one but working as well as 
this piece. I'm thinking in increase those lines so will be wonderful if I can 
optimize the code.



Este correo ha sido enviado desde el Politécnico de Informática Carlos Marx 
de Matanzas.
La gran batalla se librará en el campo de las ideas



?php

$replacements = array(
'ntilde;' = 'n',
'aacute;' = 'a',
'eacute;' = 'e',
'iacute;' = 'i',
'oacute;' = 'o',
'uacute;' = 'u',
);

$out = str_replace(array_keys($replacements), array_values($replacements), $in);





--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Martin Alterisio
2007/11/6, Alberto García Gómez [EMAIL PROTECTED]:

 I'm a mess in regular expressions and I make this code:

 $link = ereg_replace('ntilde;','n',$link);
 $link = ereg_replace('aacute;','a',$link);
 $link = ereg_replace('eacute;','e',$link);
 $link = ereg_replace('iacute;','i',$link);
 $link = ereg_replace('oacute;','o',$link);
 $link = ereg_replace('uacute;','u',$link);

 I ask if is a way to make those lines into a single one but working as
 well as this piece. I'm thinking in increase those lines so will be
 wonderful if I can optimize the code.



 Este correo ha sido enviado desde el Politécnico de Informática Carlos
 Marx de Matanzas.
 La gran batalla se librará en el campo de las ideas


Use str_replace instead of ereg_replace. You don't need regular expressions
there.
Your code is good as it is, one line per string replacemente. Don't mess up
code readability just for the sake of some lousy optimization, it's not
worthy.



(in spanish)

Usa str_replace en lugar de ereg_replace. No necesitas expresiones regulares
en este caso.
Tu código está bien así, una línea por reemplazo. No arruines la legibilidad
del código solo por una optimización inútil, no vale la pena.


Re: [PHP] Regular Expressions

2007-11-06 Thread Robert Cummings
On Tue, 2007-11-06 at 23:24 -0300, Martin Alterisio wrote:
 2007/11/6, Alberto García Gómez [EMAIL PROTECTED]:
 
  I'm a mess in regular expressions and I make this code:
 
  $link = ereg_replace('ntilde;','n',$link);
  $link = ereg_replace('aacute;','a',$link);
  $link = ereg_replace('eacute;','e',$link);
  $link = ereg_replace('iacute;','i',$link);
  $link = ereg_replace('oacute;','o',$link);
  $link = ereg_replace('uacute;','u',$link);
 
  I ask if is a way to make those lines into a single one but working as
  well as this piece. I'm thinking in increase those lines so will be
  wonderful if I can optimize the code.

?php

$map = array
(
'ntilde;', 'n',
'aacute;', 'a',
'eacute;', 'e',
'iacute;', 'i',
'oacute;', 'o',
'uacute;', 'u',
);

$link =
str_replace(
array_keys( $map ), array_values( $map ), $link );

?

The only way to make it faster is to build the key array and value array
separately, but then the association is not so clear.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Jim Lucas

Robert Cummings wrote:

On Tue, 2007-11-06 at 23:24 -0300, Martin Alterisio wrote:

2007/11/6, Alberto García Gómez [EMAIL PROTECTED]:

I'm a mess in regular expressions and I make this code:

$link = ereg_replace('ntilde;','n',$link);
$link = ereg_replace('aacute;','a',$link);
$link = ereg_replace('eacute;','e',$link);
$link = ereg_replace('iacute;','i',$link);
$link = ereg_replace('oacute;','o',$link);
$link = ereg_replace('uacute;','u',$link);

I ask if is a way to make those lines into a single one but working as
well as this piece. I'm thinking in increase those lines so will be
wonderful if I can optimize the code.


?php

$map = array
(
'ntilde;', 'n',
'aacute;', 'a',
'eacute;', 'e',
'iacute;', 'i',
'oacute;', 'o',
'uacute;', 'u',


one mistake, your commas above, between the index and value,
should be a = instead


);

$link =
str_replace(
array_keys( $map ), array_values( $map ), $link );

?

The only way to make it faster is to build the key array and value array
separately, but then the association is not so clear.

Cheers,
Rob.



--
Jim Lucas


Perseverance is not a long race;
it is many short races one after the other

Walter Elliot



Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-11-06 Thread Robert Cummings
On Tue, 2007-11-06 at 20:15 -0800, Jim Lucas wrote:
 Robert Cummings wrote:
  On Tue, 2007-11-06 at 23:24 -0300, Martin Alterisio wrote:
  2007/11/6, Alberto García Gómez [EMAIL PROTECTED]:
  I'm a mess in regular expressions and I make this code:
 
  $link = ereg_replace('ntilde;','n',$link);
  $link = ereg_replace('aacute;','a',$link);
  $link = ereg_replace('eacute;','e',$link);
  $link = ereg_replace('iacute;','i',$link);
  $link = ereg_replace('oacute;','o',$link);
  $link = ereg_replace('uacute;','u',$link);
 
  I ask if is a way to make those lines into a single one but working as
  well as this piece. I'm thinking in increase those lines so will be
  wonderful if I can optimize the code.
  
  ?php
  
  $map = array
  (
  'ntilde;', 'n',
  'aacute;', 'a',
  'eacute;', 'e',
  'iacute;', 'i',
  'oacute;', 'o',
  'uacute;', 'u',
 
 one mistake, your commas above, between the index and value,
 should be a = instead

Yeah, I didn't actually test after cutting/pasting and reformatting...
was feeling lazy... that'll learn me :)

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-05-22 Thread Zoltán Németh
2007. 05. 22, kedd keltezéssel 03.35-kor Don Don ezt írta:
 Hi all, am trying to run a regular expression to a list of user entered data 
 on some forms.
 
 I've creating what i think is a matching pattern for each category as shown 
 below:
 
 function validateEntry($regularExpression, $fieldValue)
 {
 if(preg_match($regularExpression, $fieldValue))
 {
 return true;
 }
 else
 {
 return false;
 }
 }
 
 i made a list of rules that are passed into the function above
 
 1)  [a-zA-Z][0-9] //allow any characters and numbers together anywhere within 
 the text
 2)  [a-zA-Z]  //allow only any charaters in the text
 3)  [0-9]{2}  //allow only digits and they must be 2 in length
 4)  [a-zA-Z]{1}   //allow only 1 character either uppercase or lowercase
 

the patterns seem ok, but you should enclose them within some delimiter
characters, e.g. /[a-zA-Z][0-9]/ or something like that

greets
Zoltán Németh

 
 but each of these fail the validation when data is entered appropriately , 
 seems iam getting something wrong.
 
 
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user 
 panel and lay it on 
 us.http://us.rd.yahoo.com/evt=48516/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
  hot CTA = Join Yahoo!'s user panel

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-05-22 Thread Tijnema

On 5/22/07, Zoltán Németh [EMAIL PROTECTED] wrote:

2007. 05. 22, kedd keltezéssel 03.35-kor Don Don ezt írta:
 Hi all, am trying to run a regular expression to a list of user entered data 
on some forms.

 I've creating what i think is a matching pattern for each category as shown 
below:

 function validateEntry($regularExpression, $fieldValue)
 {
 if(preg_match($regularExpression, $fieldValue))
 {
 return true;
 }
 else
 {
 return false;
 }
 }

 i made a list of rules that are passed into the function above

 1)  [a-zA-Z][0-9] //allow any characters and numbers together anywhere within 
the text
 2)  [a-zA-Z]  //allow only any charaters in the text
 3)  [0-9]{2}  //allow only digits and they must be 2 in length
 4)  [a-zA-Z]{1}   //allow only 1 character either uppercase or lowercase


the patterns seem ok, but you should enclose them within some delimiter
characters, e.g. /[a-zA-Z][0-9]/ or something like that

greets
Zoltán Németh



Yes, but make sure you don't end up with a / inside your expression,
as that would mean the end of the expression.

You could also use another delimiter in your preg functions, i prefer
using the % symbol, but you could of course use anything you want :)

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-05-22 Thread Jim Lucas

Don Don wrote:

Hi all, am trying to run a regular expression to a list of user entered data on 
some forms.

I've creating what i think is a matching pattern for each category as shown 
below:

function validateEntry($regularExpression, $fieldValue)
{
if(preg_match($regularExpression, $fieldValue))
{
return true;
}
else
{
return false;
}
}
is this all your function will ever do, or do you plan on extending it 
later?





i made a list of rules that are passed into the function above

1)  [a-zA-Z][0-9] //allow any characters and numbers together anywhere within 
the text
2)  [a-zA-Z]  //allow only any charaters in the text
3)  [0-9]{2}  //allow only digits and they must be 2 in length
4)  [a-zA-Z]{1}   //allow only 1 character either uppercase or lowercase


not sure how you are setting these up, but try something like this

$slpnum   = '!^[a-zA-Z0-9]+$!';
$slpha= '!^[a-zA-Z]+$!';
$number   = '!^[0-9]{2}$!';
$aplshort = '!^[a-zA-Z]{1}$!';





but each of these fail the validation when data is entered appropriately , 
seems iam getting something wrong.


   Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user 
panel and lay it on 
us.http://us.rd.yahoo.com/evt=48516/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
 hot CTA = Join Yahoo!'s user panel



--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Unknown

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2007-05-22 Thread Jochem Maas
Don Don wrote:
 Hi all, am trying to run a regular expression to a list of user entered data 
 on some forms.
 
 I've creating what i think is a matching pattern for each category as shown 
 below:
 
 function validateEntry($regularExpression, $fieldValue)
 {
 if(preg_match($regularExpression, $fieldValue))
 {
 return true;
 }
 else
 {
 return false;
 }
 }
 

this function sucks - it does nothing more than wrap preg_match and
returns strings instead of boolean values.

regexp's become hard very quickly - but for simple checks like your
doing your probably better off using the functions in the ctype
extension:

http://php.net/ctype

 i made a list of rules that are passed into the function above
 
 1)  [a-zA-Z][0-9] //allow any characters and numbers together anywhere within 
 the text
 2)  [a-zA-Z]  //allow only any charaters in the text
 3)  [0-9]{2}  //allow only digits and they must be 2 in length
 4)  [a-zA-Z]{1}   //allow only 1 character either uppercase or lowercase
 
 
 but each of these fail the validation when data is entered appropriately , 
 seems iam getting something wrong.

how exactly do you define these regexps? seems like your forgetting to add a 
start/end delimiting
character to the regexp strings (as others have pointed out).

 
 
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user 
 panel and lay it on 
 us.http://us.rd.yahoo.com/evt=48516/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
  hot CTA = Join Yahoo!'s user panel

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions

2006-11-30 Thread tedd

At 11:42 PM +0200 11/29/06, Dotan Cohen wrote:

On 20/11/06, Paul Novitski [EMAIL PROTECTED] wrote:
-snip-
Paul, I just got around to reading this thread. The post of yours that
I quote above has got to be one of the best posts that I've read in
the 5 years that I've been on and off the php list. The way you break
that regex down taught me things that have eluded me for half a
decade. Although I have nothing to do with the OP, I really want to
say thanks for that bit of information.



Paul:

Same here -- and I saved your explanation in my references to 
review. You ought to put that on your site.


Very well done.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions

2006-11-29 Thread Dotan Cohen

On 20/11/06, Paul Novitski [EMAIL PROTECTED] wrote:


Børge,

Here's how I would think this one through:

First, I'm having to make several guesses at the nature of your text content:

- You use the single word topic but I'll assume
this can be multiple words and spaces.

- Your source string includes a space after rest
of the text  while your marked-up result
doesn't.  However I will assume that you really
do mean the rest of the text until end-of-string.

- Your source string also includes a space before
the initial c but your regexp pattern
doesn't.  I'll assume that both beginning and ending spaces are unintentional.


Your source string:

 c FF topic c 99 rest of the text

consists of these parts:

1) [start-of-string]
2) c 
3) FF (color code 1)
4)  
5) topic  (text 1)
6)  c 
7) 99 (color code 2)
8)  
9) rest of the text   (text 2)
10) [end-of-string]

i.e.:

1) [start-of-string]
2) c + whitespace
3) color code 1
4) whitespace
5) one or more characters
6) whitespace + c + whitespace
7) color code 2
8) whitespace
9) one or more characters
10) [end-of-string]

This suggests the regexp pattern:

1) ^
2) c\s
3) ([0-9A-F]{6})
4) \s
5) (.+)
6) \sc\s
7) ([0-9A-F]{6})
8) \s
9) (.+)
10) $

/^c\s([0-9A-F]{6})\s(.+)\sc\s([0-9A-F]{6})\s(.+)$/i

Everything in the source string that you need to
retain needs to be in parentheses so regexp can grab it.

In 5) I can let the pattern be greedy, safe in
the knowledge that there WILL be a /sc to terminate the character-grab.

I end with the pattern modifier /i so it will
work with lowercase letters in the RGB color codes.

PHP:

$sText = 'c FF topic c 99 rest of the text';
$sPattern = '/^c\s([0-9A-F]{6})\s(.+)\sc\s([0-9A-F]{6})\s(.+)$/i';
preg_match($sPattern, $sText, $aMatches);
print_r($aMatches);

result:

Array
(
 [0] = c FF topic c 99 rest of the text
 [1] = FF
 [2] = topic
 [3] = 99
 [4] = rest of the text
)

This isolates the four substrings you want in regexp references $1 through $4.

Replacement:

[Tangentially, I'd like to comment that font tags
are passe.  I urge you to use spans with styling
instead.  I normally dislike using inline styles
(style details mixed with the HTML), but in this
case (as far as I know) you don't have any
choice.  If you can, I suggest you replace the
literal color codes with style names and define
the precise colors in your stylesheet, not your database.

[What this further suggests is that you ought to
have two discrete database fields, `topic` and
`description`, if you can, rather than combining
them into one field that needs to be
parsed.  Then you can output something like:

 span class=topicTOPIC/span span class=descDESCRIPTION/span

and leave the RGB color codes out of this layer
of your application altogether.]


However, working with the data you've been dealt:

$sTagBegin = 'span style=color:#';
$sTagEnd = ';';
$sCloseTag = '/span';

$sReplacement = $sTagBegin . '$1' . $sTagEnd . '$2' . $sCloseTag .
 $sTagBegin . '$3' . $sTagEnd . '$4' . $sCloseTag;

echo preg_replace($sPattern, $sReplacement, $sText);

result:

span style=color:#FF;topic/span span
style=color:#99;rest of the text/span



It's tempting to write the pattern more
succinctly to take advantage of the repeating pattern of the source text:

 c COLORCODE text

The regexp pattern might be:

1) \s*
2) c\s
3) ([0-9A-F]{6})
4) \s
5) ([^]+)

1) optional whitespace
2) c + whitespace
3) color code
4) whitespace
5) one or more characters until the next 

$sText = 'c FF topic c 99 rest of the text';

$sPattern = '/\s*c\s([0-9A-F]{6})\s([^]+)/i';

preg_match_all($sPattern, $sText, $aMatches);

result:

Array
(
 [0] = Array
 (
 [0] =  FF topic
 [1] =  99 rest of the text
 )

 [1] = Array
 (
 [0] = FF
 [1] = 99
 )

 [2] = Array
 (
 [0] = topic
 [1] = rest of the text
 )

)

In this case, we need to specify the tag pattern only once:

$sReplacement = $sTagBegin . '$1' . $sTagEnd . '$2' . $sCloseTag;

echo preg_replace($sPattern, $sReplacement, $sText);

result:

span style=color:#FF;topic /span span
style=color:#00FF00;rest of the text/span

Notice is that this results in whitespace after
the topic string.  Someone more knowledgeable in
regular expressions can probably tell you how to
eliminate that, perhaps by using a regexp assertion:
http://php.net/manual/en/reference.pcre.pattern.syntax.php#regexp.reference.assertions

Regards,
Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com



Paul, I just got around to reading this thread. The post of yours that
I quote above has got to be one of the best posts that I've read in
the 5 years that I've been on and off the php list. The way you break
that regex down taught me things that 

Re: [PHP] Regular expressions

2006-11-15 Thread John Meyer
Darrell Brogdon wrote:
 Can you elaborate a little?  Do you mean that you want certain letters
 to have a numeric representation?
 
 -D


no, what I was meaning was in relationship to each other, whether they
are the same letter or not.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-11-15 Thread Dave Goodchild

Is there a way to make a regular expression to match on a particular way
the letters are arranged?  For instance, if you had a word:

THAT


It could match on any word in the dictionary that had the form:

1231

preg_,match('/^(\w){1}\w\w\1$/');

would match the above on a single line for example, where \1 refers to the
pattern captured in parentheses at the start.

Try and be a little more specific in what you want to match, as regex is
hard enough to start with - a detailed and clear description will elicit
corresponding responses.


Re: [PHP] Regular expressions

2006-11-15 Thread John Meyer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Okay, what I am referring to is cryptograms, where one letter is
substituted for another.  I would like to be able to list all the words
in a dictionary that have that arrangement of their letters.  Later on,
I would like to be able to do an entire cryptogram that way.
Dave Goodchild wrote:
 Is there a way to make a regular expression to match on a particular way
 the letters are arranged?  For instance, if you had a word:
 
 THAT
 
 
 It could match on any word in the dictionary that had the form:
 
 1231
 
 preg_,match('/^(\w){1}\w\w\1$/');
 
 would match the above on a single line for example, where \1 refers to
 the pattern captured in parentheses at the start.
 
 Try and be a little more specific in what you want to match, as regex is
 hard enough to start with - a detailed and clear description will elicit
 corresponding responses.

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFWwXkbHd4gglFmoARAooyAJ0S8R3JkLApczGxBA9FrOQQMZSGvwCgmNUX
C9idJue2LWK1EL6gO6qttjg=
=IqlT
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-11-15 Thread David Tulloh

John Meyer wrote:

Is there a way to make a regular expression to match on a particular way
the letters are arranged?  For instance, if you had a word:

THAT


It could match on any word in the dictionary that had the form:

1231

  


I think something like this might be possible using lookbehind assertions.
It's not the kind of pattern that regex was designed for though, it 
would probably be easier to write the processing using PHP character 
indexing.



David

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-11-14 Thread Darrell Brogdon
Can you elaborate a little?  Do you mean that you want certain  
letters to have a numeric representation?


-D

On Nov 14, 2006, at 6:57 PM, John Meyer wrote:

Is there a way to make a regular expression to match on a  
particular way

the letters are arranged?  For instance, if you had a word:

THAT


It could match on any word in the dictionary that had the form:

1231

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






Darrell Brogdon
[EMAIL PROTECTED]
http://darrell.brogdon.net

*
** Prepare for PHP Certication!**
** http://phpflashcards.com**
*




Re: [PHP] Regular expressions

2006-10-17 Thread Richard Lynch
On Mon, October 16, 2006 4:01 pm, Curt Zirzow wrote:
 That makes me wonder.. according to the docs U inverts greediness, if
 you have...
 /foo.*?bar/U

 does that make .*? a greedy .*

I believe I stubbed my toe on that fact once, yes...

I always manage to mess up the greedy/ungreedy stuff, and then throw
up my hands and try to use an expression to look for a specific
character to be there or not there, and then I don't have to worry
about the greedy stuff as much...

Sometimes, though, you have to grit your teeth and dink with ? and U
until it works.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 4:19 pm, Morten Twellmann wrote:
 I'm trying to understand these regular expressions, but I can't make
 them
 work...

 All I want to do, is to find the first occurrence of some text inside
 the
 HTML tags h1 and /h1.

 Example string: pOctober 14, 2006/ph1Welcome to my
 homepage/h1pWe're happy to announce.../p

 must return:

 Welcome to my homepage


 I tried with:

 preg_match('h1\b[^]*(.*?)/h1', h1Welcome to my homepage/h1,
 $matches, PREG_OFFSET_CAPTURE);
 print_r($matches);

 but got nothing...

 Can anyone tell me how to do this?

 (I tried the above expression in EditPad Pro 6 and it worked...!)

Download The Regex Coach and play with that -- It's not 100% the
same as PHP, and the escaping of backslashes for PHP isn't in it, but
it rocks for visual presentation of pattern/match

Your main problem is a lack of start/end delimiters for the pattern:
'|h1[^]*(.*)/h1|ims'
would probably be better.
| at beginning/end as pattern delimiters
i becase H1 and h1 are both the same tag in HTML
ms because newlines inside the text are okay
Take out the \b because I dunno what it does, but you don't need it.
.*? is kinda silly -- .* mean 0 or more characters, and ? means
maybe but putting them together has no added value, so lose the ?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Chrome [EMAIL PROTECTED] wrote:

*edit* sorry I didn't think and just hit reply on this instead of reply
all... sorry Richard */edit*

[snip]
.*? is kinda silly -- .* mean 0 or more characters, and ? means maybe
but putting them together has no added value, so lose the ?
[/snip]

I could be wrong (and under the considerable knowledge of Richard I
certainly feel it :) ) but doesn't the ? after a quantifier signify that
preceding pattern is to be taken as ungreedy?


Yes, this is correct. ? after * means means  ungreedy in this paticular match.


Curt.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 2:54 pm, Chrome wrote:
 *edit* sorry I didn't think and just hit reply on this instead of
 reply
 all... sorry Richard */edit*

 [snip]
 .*? is kinda silly -- .* mean 0 or more characters, and ? means
 maybe
 but putting them together has no added value, so lose the ?
 [/snip]

 I could be wrong (and under the considerable knowledge of Richard I
 certainly feel it :) ) but doesn't the ? after a quantifier signify
 that
 preceding pattern is to be taken as ungreedy?

You're right; I'm wrong.

I'm not PCRE expert.

Took me 20 years to be able to stumble through the simplest expressions.

? means maybe in some other place in PCRE.  Or maybe that's POSIX. 
Never have figured that one out.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regular expressions

2006-10-16 Thread Chrome
[snip]
? means maybe in some other place in PCRE.  Or maybe that's POSIX. 
Never have figured that one out.
[/snip]

? directly after an expression is equivalent to {0,1} (maybe) but after a
quantifier (*, +, {}) means ungreedy

I'm sure I'll be corrected if I'm wrong :)

Dan

-- 
http://chrome.me.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Morten Twellmann
Great! It works! Thank you very much.

Also thanks to all the other guys who answered. I also think I finally
started to understand these regular expressions a bit better.

- Morten

- Original Message - 
From: Richard Lynch [EMAIL PROTECTED]
To: Morten Twellmann [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Monday, October 16, 2006 7:42 PM
Subject: Re: [PHP] Regular expressions


 On Sat, October 14, 2006 4:19 pm, Morten Twellmann wrote:
  I'm trying to understand these regular expressions, but I can't make
  them
  work...
 
  All I want to do, is to find the first occurrence of some text inside
  the
  HTML tags h1 and /h1.
 
  Example string: pOctober 14, 2006/ph1Welcome to my
  homepage/h1pWe're happy to announce.../p
 
  must return:
 
  Welcome to my homepage
 
 
  I tried with:
 
  preg_match('h1\b[^]*(.*?)/h1', h1Welcome to my homepage/h1,
  $matches, PREG_OFFSET_CAPTURE);
  print_r($matches);
 
  but got nothing...
 
  Can anyone tell me how to do this?
 
  (I tried the above expression in EditPad Pro 6 and it worked...!)

 Download The Regex Coach and play with that -- It's not 100% the
 same as PHP, and the escaping of backslashes for PHP isn't in it, but
 it rocks for visual presentation of pattern/match

 Your main problem is a lack of start/end delimiters for the pattern:
 '|h1[^]*(.*)/h1|ims'
 would probably be better.
 | at beginning/end as pattern delimiters
 i becase H1 and h1 are both the same tag in HTML
 ms because newlines inside the text are okay
 Take out the \b because I dunno what it does, but you don't need it.
 .*? is kinda silly -- .* mean 0 or more characters, and ? means
 maybe but putting them together has no added value, so lose the ?

 -- 
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Richard Lynch [EMAIL PROTECTED] wrote:

On Mon, October 16, 2006 2:54 pm, Chrome wrote:
 *edit* sorry I didn't think and just hit reply on this instead of
 reply
 all... sorry Richard */edit*

 [snip]
 .*? is kinda silly -- .* mean 0 or more characters, and ? means
 maybe
 but putting them together has no added value, so lose the ?
 [/snip]

 I could be wrong (and under the considerable knowledge of Richard I
 certainly feel it :) ) but doesn't the ? after a quantifier signify
 that
 preceding pattern is to be taken as ungreedy?

You're right; I'm wrong.

I'm not PCRE expert.

Took me 20 years to be able to stumble through the simplest expressions.

? means maybe in some other place in PCRE.  Or maybe that's POSIX.
Never have figured that one out.


The ? after * means ungreedy only.. so your basic:
 a? means a or no a in the regular usage

The easiest to remember is that ? two basic definitions:
 - extend the meaning of
 - 0 or 1 of the previous expression



/foo(?i)bar/

matches FOoBar, fOObar, foobar.. the (?i) extends the meaning of
(?[modifer-list])  to contain modifiers of the previous expression and
no more

/foo.*?bar/
 is the same thing as saying /foo.*(?U)bar; a short cut, much like
what \d is a shortcut to [0-9]

/foo(?)/
 a look behind assertion

/foo(?=...)/
 a look ahead assertion

(and a negative of the  assertions are allowed)

/foo(?(condition)yes:no)/
 condition usually being an assoertion of some sort


I still dont understand it, and it is one of the reasons why people
have problems using regex, it really is a whole different language,
using Regex Coach as chrome did, is the probably the best way to find
out the problem or how to match what you are looking for...

A nice little overview (although i have read it about a few dozen
times and still cant apply the logic 100% of the time)
php.net/reference.pcre.pattern.syntax.php

on the other hand, people still want html parsers written in PCRE.. :)


Curt.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Chrome [EMAIL PROTECTED] wrote:

[snip]
? means maybe in some other place in PCRE.  Or maybe that's POSIX.
Never have figured that one out.
[/snip]

? directly after an expression is equivalent to {0,1} (maybe) but after a
quantifier (*, +, {}) means ungreedy


I kind of talked about this in the reply to richard the .*? is exactly
the same as doing .*(?U)

an inline modifier to the previous expression.

That makes me wonder.. according to the docs U inverts greediness, if
you have...
/foo.*?bar/U

does that make .*? a greedy .*

Curt.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regular expressions

2006-10-16 Thread Chrome
On 10/16/06, Chrome [EMAIL PROTECTED] wrote:
 [snip]
 ? means maybe in some other place in PCRE.  Or maybe that's POSIX.
 Never have figured that one out.
 [/snip]

 ? directly after an expression is equivalent to {0,1} (maybe) but
 after a quantifier (*, +, {}) means ungreedy

I kind of talked about this in the reply to richard the .*? is exactly
the same as doing .*(?U)

an inline modifier to the previous expression.

That makes me wonder.. according to the docs U inverts greediness, if
you have...
/foo.*?bar/U

does that make .*? a greedy .*

Curt.

Good point... I suppose it would... I'm not au fait with greediness in
honesty... I just remember the syntax

Strange really because I'm arguing with a regex at the minute lol

Dan

-- 
http://chrome.me.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-14 Thread Penthexquadium
On Sat, 14 Oct 2006 23:19:13 +0200, Morten Twellmann [EMAIL PROTECTED] 
wrote:
 I'm trying to understand these regular expressions, but I can't make them
 work...
 
 All I want to do, is to find the first occurrence of some text inside the
 HTML tags h1 and /h1.
 
 Example string: pOctober 14, 2006/ph1Welcome to my
 homepage/h1pWe're happy to announce.../p
 
 must return:
 
 Welcome to my homepage
 
 
 I tried with:
 
 preg_match('h1\b[^]*(.*?)/h1', h1Welcome to my homepage/h1,
 $matches, PREG_OFFSET_CAPTURE);
 print_r($matches);
 
 but got nothing...
 
 Can anyone tell me how to do this?
 
 (I tried the above expression in EditPad Pro 6 and it worked...!)
 
 Sincerely,
 
 Morten Twellmann

The regex you wrote lacks separator. That PHP statement will occur an
error:

 Warning: preg_match() [function.preg-match]: Unknown modifier ']' in
 /path/file.php on line X

The statement should be:

preg_match(/h1\b[^]*(.*?)\/h1/i, h1Welcome to my homepage/h1,
$matches, PREG_OFFSET_CAPTURE);
print_r($matches);

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions or something else?

2006-04-12 Thread Kim Christensen
On 4/12/06, Chris Westbrook [EMAIL PROTECTED] wrote:
 I have a problem.  I'm trying to get a Google search results page via snoopy
 and then display the links of the results it returns in an application.  I
 know about the fetchlinks function in snoopy, but I'm having trouble getting
 the text between the a and /a tags.  Yeah, I know, I should use the
 Google API, but my client doesn't want me doing that, probably because they
 might have to pay for that.  any suggestions?

Try this, and read up on regular expressions - it's an essential
knowledge if you're a programmer.

$text = this is where the contents of your search result page goes;
preg_match_all('|a[^]*href=([^]+)[^]*([^]+)\/a|U', $text,
$links, PREG_SET_ORDER);
print_r($links);

--
Kim Christensen
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] regular expressions and Phone validation

2006-03-15 Thread Jay Blanchard
[snip]
I have one small problem I don't understand the preg_replace() method.
 I understand the gist of what it does but I still don't fully know
what it does.  I have read the entry in the php manual about this and
I am still confused about it. I've never been any good with regular
expressions.

Here is the function in use:

function checkPhone ($Phone)
{
global $errmsg;
if (!empty($Phone))
{
$Phone = ereg_replace([^0-9], '', $Phone);

if ((strlen($Phone)) = 14)
return
preg_replace(/[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4}).*/,
(\\1) \\2-\\3,$Phone);
}
}

I think my problem is mostly what is returned when preg_replace
executes?
[/snip]

There are several methods of doing phone number validation, one was even
mentioned last week. You may try the archives for answers.

What are you trying to do here? Once we know that we can probably help
you.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2005-10-09 Thread Jasper Bryant-Greene

Gustav Wiberg wrote:

?php
$lines = file('export/nhExportVarupiraten.txt');

// Loop through our array, show HTML source as HTML source; and line 
numbers too.

foreach ($lines as $line_num = $line) {

echo Line #b{$line_num}/b :  . htmlspecialchars($line) . br /\n;

if ($line_num  0 ) {
 $getName = explode('', $line);
 $pattern = /ID=([0-9]*)\/;
 $subject = $line;
 $idNumber = preg_split($pattern, $subject);


// instead of preg_split, use preg_match

$idNumber = preg_match($pattern, $subject, $matches);

// your ID number is now in $matches[1]



 echo NAME =  . $getName[2] .  has ID number=$idNumber[0]br;
}
//require(phpfunctions/opendb.php);
//$sql = UPDATE beskrivandeVarunamn= . safeQuote($bNamn) .  WHERER
//mysql_close();

}

?


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2005-10-09 Thread Gustav Wiberg
- Original Message - 
From: Jasper Bryant-Greene [EMAIL PROTECTED]

To: PHP General php-general@lists.php.net
Sent: Sunday, October 09, 2005 8:06 PM
Subject: Re: [PHP] Regular expressions



Gustav Wiberg wrote:

?php
$lines = file('export/nhExportVarupiraten.txt');

// Loop through our array, show HTML source as HTML source; and line 
numbers too.

foreach ($lines as $line_num = $line) {

echo Line #b{$line_num}/b :  . htmlspecialchars($line) . br 
/\n;


if ($line_num  0 ) {
 $getName = explode('', $line);
 $pattern = /ID=([0-9]*)\/;
 $subject = $line;
 $idNumber = preg_split($pattern, $subject);


// instead of preg_split, use preg_match

$idNumber = preg_match($pattern, $subject, $matches);

// your ID number is now in $matches[1]



 echo NAME =  . $getName[2] .  has ID number=$idNumber[0]br;
}
//require(phpfunctions/opendb.php);
//$sql = UPDATE beskrivandeVarunamn= . safeQuote($bNamn) .  WHERER
//mysql_close();

}

?


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/124 - Release Date: 
2005-10-07




Hi there!

Thanx, I'll try that! :-)

/G
http://www.varupiraten.se/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions book

2005-08-10 Thread Anas Mughal
The best I found is:

O'Reilly book - Mastering Regular Expressions




On 8/3/05, -k. [EMAIL PROTECTED] wrote:
 
 Has anyone here tried to learn Regular expressions with RegexBuddy?
 
 http://www.regular-expressions.info/regexbuddy.html
 
 It looks pretty cool, and even has some PHP specific stuff, but you have 
 to pay to play.
 
 
 
 
 -k.
 
 __
 Do You Yahoo!?
 Tired of spam? Yahoo! Mail has the best spam protection around
 http://mail.yahoo.com
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



Re: [PHP] Regular expressions book

2005-08-03 Thread Edward Vermillion

Stefan Lemmen wrote:

Hi,

I've want to dig a bit deeper into regular expressions for php.
I wonder if anyone can help me choosing between 2 books I'm considering buying:

1. Open Source Regular Expression Recipes - Nathan A Good
2. Mastering Regular Expressions - Jeffrey Freidl

If your using/reading one of these books, please let me know which one
is best for PHP regex.

Thnx

Stefan Lemmen
Apeldoorn Holland



Haven't read the first, but the second is very good. It really helped me 
to grasp the concepts of regex.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions book

2005-08-03 Thread Steve Turnbull
On Wed, 03 Aug 2005 12:10:40 -0500, Edward Vermillion wrote:

 Stefan Lemmen wrote:
 Hi,
 
 I've want to dig a bit deeper into regular expressions for php.
 I wonder if anyone can help me choosing between 2 books I'm considering 
 buying:
 
 1. Open Source Regular Expression Recipes - Nathan A Good
 2. Mastering Regular Expressions - Jeffrey Freidl
 
 If your using/reading one of these books, please let me know which one
 is best for PHP regex.
 
 Thnx
 
 Stefan Lemmen
 Apeldoorn Holland
 
 
 Haven't read the first, but the second is very good. It really helped me 
 to grasp the concepts of regex.

Also, you could try the O'Reilly book - Mastering Regular Expressions.
It's hardly bedside reading, but very thorougher.

It isn't PHP specific, but it is a very good guide from the ground up. It
isn't very good for 'quick reference' cookbook type stuff, but it will
give you a very good understanding of regex.

If you run Linux as a OS, there are a couple of regex gui's
(KregExpEditor for KDE) which are helpful. You 'design' the expression in
the interface and it gives you the actual reular exp as the result. I
am finding this a good way of learning, i.e. figuring out how the result
came about...

Just my thoughts...

Steve

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions book

2005-08-03 Thread -k.
Has anyone here tried to learn  Regular expressions with RegexBuddy?

http://www.regular-expressions.info/regexbuddy.html

It looks pretty cool, and even has some PHP specific stuff, but you have to pay 
to play.




-k.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions problem

2005-04-30 Thread Khorosh Irani
For example I want to math this stream:
123 mm  334
What is the pattern that math with this stream?
Thanks

On 4/29/05, Malcolm Mill [EMAIL PROTECTED] wrote:
 What is it you want to do?
 
 On 4/29/05, Khorosh Irani [EMAIL PROTECTED] wrote:
  Hello
  I have a question:
  What is in the role of space in the regular expressions (POSIX)?
 
  --
  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] Regular expressions problem

2005-04-30 Thread Rasmus Lerdorf
Khorosh Irani wrote:
For example I want to math this stream:
123 mm  334
What is the pattern that math with this stream?
Thanks
123[[:space:]]+mm[[:space:]]+334
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular expressions problem

2005-04-30 Thread Matthew Weier O'Phinney
* Khorosh Irani [EMAIL PROTECTED]:
 For example I want to math this stream:
 123 mm  334
 What is the pattern that math with this stream?

Depends on what regexp function you use, what exactly you want to match,
and whether or not you want to know, after you match, any of the
segments. Rasmus has given you one possible pattern that works with the
ereg functions. If you wanted to use a preg function and wanted to match
3 digits, a space, two m', one or more spaces, and 3 digits, you would
use:

preg_match('/^\d{3} mm\s+\d{3}$/', $string);

But, what it all comes down to is: you need to determine what PATTERN
you need to be able to match. Once you know that, you can write the
regexp.

 On 4/29/05, Malcolm Mill [EMAIL PROTECTED] wrote:
  What is it you want to do?
  
  On 4/29/05, Khorosh Irani [EMAIL PROTECTED] wrote:
   Hello
   I have a question:
   What is in the role of space in the regular expressions (POSIX)?

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions

2005-04-14 Thread Erwin Kerk
pete M wrote:
I've been messing about with this for a while to no avail.. so help 
would be appreciates

I'm new to regular expressions and tried this with preg_replace, now I'm 
using eregi_replace !

here's the text
$txt = 'span style=font-size: 10pt; font-family: Times New 
Roman;Itbr /
blahh blahhh blahhh ofbr /
/span';

what I want to do it take the font-size and font-family attributes out so
style=font-size: 10pt; font-family: Times New Roman;
beomes
style=  
and the php
$pattern = 'font-size:*\;';
$txt = eregi_replace($replace,'',$txt);
$pattern = 'font-family:*\;';
$txt = eregi_replace($replace,'',$txt);
What I'm trying to do is match the font-size: and replace everything up 
to the ; with '' ie nothing

dont work
Feel I'm so close ;-(
tia
Pete

Try this:
$pattern = 'font\-size:.*?\;';

Erwin Kerk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions

2005-04-14 Thread pete M
The pattern
$pattern = 'font\-size:.*?\;';
throwns the error
eregi_replace(): REG_BADRPT
Erwin Kerk wrote:
pete M wrote:
I've been messing about with this for a while to no avail.. so help 
would be appreciates

I'm new to regular expressions and tried this with preg_replace, now 
I'm using eregi_replace !

here's the text
$txt = 'span style=font-size: 10pt; font-family: Times New 
Roman;Itbr /
blahh blahhh blahhh ofbr /
/span';

what I want to do it take the font-size and font-family attributes 
out so
style=font-size: 10pt; font-family: Times New Roman;
beomes
style=  

and the php
$pattern = 'font-size:*\;';
$txt = eregi_replace($replace,'',$txt);
$pattern = 'font-family:*\;';
$txt = eregi_replace($replace,'',$txt);
What I'm trying to do is match the font-size: and replace everything 
up to the ; with '' ie nothing

dont work
Feel I'm so close ;-(
tia
Pete

Try this:
$pattern = 'font\-size:.*?\;';

Erwin Kerk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions

2005-04-14 Thread Erwin Kerk
pete M wrote:
The pattern
$pattern = 'font\-size:.*?\;';
throwns the error
eregi_replace(): REG_BADRPT
Well, this should work (tested and all )
$pattern=|font\-size:.*?;|si;
$txt = preg_replace( $pattern, , $txt );
Erwin
--

  mail   : [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]
  msn: [EMAIL PROTECTED]
  jabber : [EMAIL PROTECTED]
  skype  : erwinkerk
  hello  : vlits

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions

2005-04-14 Thread pete M
Thankyou
Diolch
danka
There seems to be a big difference between eregi_replace() and preg_replace
Am reding teh Sams - Regular Expressions in 10 mins bu the syntax seems 
ot be different. !!

regards
pete
Erwin Kerk wrote:
pete M wrote:
The pattern
$pattern = 'font\-size:.*?\;';
throwns the error
eregi_replace(): REG_BADRPT
Well, this should work (tested and all )
$pattern=|font\-size:.*?;|si;
$txt = preg_replace( $pattern, , $txt );
Erwin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular expressions

2005-04-12 Thread Jason Wong
On Tuesday 12 April 2005 18:30, jem777 wrote:
 Php docs are quite messy about what works with what function...
 This is my problem; I want to strip out spaces from my tags:

 $word = [ / quote ];
 $word = eregi_replace([[[:blank:]]*quote[[:blank:]]*], [quote],
 $word); $word =
 eregi_replace([[[:blank:]]*\/[[:blank:]]*quote[[:blank:]]*],
 [/quote], $word);

 I would expect the result to be: [/quote] but it is [ /[quote].
 It seems the first replace actually do the replace, but the how does it
 match the slash / ???

  preg_replace('|\[\s*/\s*quote\s*]|', '[/quote]', $word);

You might want to spice it up with some ungreedy modifiers.

-- 
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] Regular expressions

2005-04-12 Thread jem777
ok for this 2:

$body = preg_replace('|\[\s*quote\s*\]|', '[quote]', $body);
$body = preg_replace('|\[\s*/\s*quote\s*\]|', '[/quote]', $body);

but have these next instructions the same result?

$body = eregi_replace(\[ *quote *\], [quote], $body);
$body = eregi_replace(\[ */ *quote *\], [/quote], $body);



Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 12 April 2005 18:30, jem777 wrote:
  Php docs are quite messy about what works with what function...
  This is my problem; I want to strip out spaces from my tags:
 
  $word = [ / quote ];
  $word = eregi_replace([[[:blank:]]*quote[[:blank:]]*], [quote],
  $word); $word =
  eregi_replace([[[:blank:]]*\/[[:blank:]]*quote[[:blank:]]*],
  [/quote], $word);
 
  I would expect the result to be: [/quote] but it is [ /[quote].
  It seems the first replace actually do the replace, but the how does it
  match the slash / ???

   preg_replace('|\[\s*/\s*quote\s*]|', '[/quote]', $word);

 You might want to spice it up with some ungreedy modifiers.

 -- 
 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] Regular Expressions?

2005-04-08 Thread Chris W. Parker
[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
on Friday, April 08, 2005 3:43 PM said:

 The ' apostrophe or  can cause an early truncation of the data. My
 code thinks that the closing identifier is after the word Joe and the
 rest of the input is lost. Further, if the data does get by and it
 could possibly break a SQL statement.   
 
 Am I right in thinking the solution in this matter is using regular
 expressions?

If I understand you correctly the answer to that question is 'no'.

 If so, where is a good resource to polish my skills?

A great utility for practicing with regular expressions is theregexcoach
(search for it).

 What about turning off/on magic quotes?

I would keep magic quotes off and do the escaping myself. This way you
know exactly what is happening.

What you need to do is addslashes() to the data before putting it in the
sql query.



HTH,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regular Expressions?

2005-04-08 Thread list_php_general
Ok that would solve my SQL statements from breaking but how about in the 
submitted form data at submit time?

John

[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
on Friday, April 08, 2005 3:43 PM said:

 The ' apostrophe or  can cause an early truncation of the data. My
 code thinks that the closing identifier is after the word Joe and the
 rest of the input is lost. Further, if the data does get by and it
 could possibly break a SQL statement.   
 
 Am I right in thinking the solution in this matter is using regular
 expressions?

If I understand you correctly the answer to that question is 'no'.

 If so, where is a good resource to polish my skills?

A great utility for practicing with regular expressions is theregexcoach
(search for it).

 What about turning off/on magic quotes?

I would keep magic quotes off and do the escaping myself. This way you
know exactly what is happening.

What you need to do is addslashes() to the data before putting it in the
sql query.



HTH,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regular Expressions?

2005-04-08 Thread Chris W. Parker
[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
on Friday, April 08, 2005 4:08 PM said:

 Ok that would solve my SQL statements from breaking but how about in
 the submitted form data at submit time?

Do you mean you're having this problem?

input type=text name=.. value=She said Hi! /

?

If so, do htmlentities() to the data being displayed. That will turn the
 into quot; which will not get the form confused.



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions?

2005-04-08 Thread dan
[EMAIL PROTECTED] wrote:
Windows 2000 Server
IIS 5/Apache 1.3.33
MySQL 4.1.1
Smarty 2.6.9
PHP 5.0.3
Hi all,
I am looking for help handling a form input to SQL. I believe the solution has to do with regular expressions.
My big problem is that when a user submits data such as: 

Joe's Crabshack
The ' apostrophe or  can cause an early truncation of the data. My code thinks 
that the closing identifier is after the word Joe and the rest of the input is lost. 
Further, if the data does get by and it could possibly break a SQL statement.
Am I right in thinking the solution in this matter is using regular expressions? If so, where is a good resource to polish my skills? 

What about turning off/on magic quotes?
John
If you don't plan on doing anything this weekend, pick yourself up a 
copy of O'Reilly's Regular Expressions.  It's The Owl Book, by the cover.

The reason why I ask if you have all weekend is because it's a good 
book, but at 300+ pages, it's a good read.  I still don't know my 
regex's very well, but then again, I just kinda skipped through it. 
However, it is laid out in a format that makes it a very good reference 
book, so if you're looking to do something, then this book makes it easy 
to piece things together and find a regex that works quite well.

Thanks
-dant
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expressions?

2005-04-08 Thread John Nichel
[EMAIL PROTECTED] wrote:
snip
Joe's Crabshack
The ' apostrophe or  can cause an early truncation of the data. My code thinks 
that the closing identifier is after the word Joe and the rest of the input is lost. 
Further, if the data does get by and it could possibly break a SQL statement.
Am I right in thinking the solution in this matter is using regular expressions? If so, where is a good resource to polish my skills? 

What about turning off/on magic quotes?
John
No need for a regex.  Use something like mysql_escape_string() or 
addslashes().  That's what these functions are made for.

The Camel book is a good place to start your regex learning.
--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expressions?

2005-04-08 Thread Richard Lynch
On Fri, April 8, 2005 3:43 pm, [EMAIL PROTECTED] said:
 I am looking for help handling a form input to SQL. I believe the solution
 has to do with regular expressions.
 My big problem is that when a user submits data such as:

 Joe's Crabshack

 The ' apostrophe or  can cause an early truncation of the data. My code
 thinks that the closing identifier is after the word Joe and the rest of
 the input is lost. Further, if the data does get by and it could possibly
 break a SQL statement.

 Am I right in thinking the solution in this matter is using regular
 expressions? If so, where is a good resource to polish my skills?

You would be far better off using the built-in mysql_escape_string (recent
PHP versions) or http://php.net/addslashes

You might want to try to use Regex as an exercise, but this ain't the
place for it on a real site.

-- 
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] regular expressions ?

2005-01-28 Thread Robin Vickery
On Thu, 27 Jan 2005 11:36:39 -0800, Rick Fletcher [EMAIL PROTECTED] wrote:

 /^(1?[1-9]|[12]0)$/ works too.  The first part covers 1-9, 11-19; the
 second part gets you 10 and 20.
 
 Plus, it's ever so slightly shorter!  And isnt' that what's most
 important? :P

absolutely, and you managed it without a typo, unlike me :(

  -robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Marek Kilimajer
Zouari Fourat wrote:
Hello,
I need to verify if $x is between 1 and 20 and i need to do that with
regular expressions ?
anyone can help me outta there ?
thanks a lot
http://www.php.net/operators.comparison
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] regular expressions ?

2005-01-27 Thread Jay Blanchard
[snip]
I need to verify if $x is between 1 and 20 and i need to do that with
regular expressions ?
anyone can help me outta there ?
[/snip]

Why regex? 

if((1  $x)  ($x  20)){
it's true
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Leif Gregory
Hello Zouari,

Thursday, January 27, 2005, 7:33:04 AM, you wrote:
Z I need to verify if $x is between 1 and 20 and i need to do that
Z with regular expressions ?

If you *need* to do it with regexp, try this:



if (preg_match(/[2-19]/,$x))
  echo It is!;





If 1 and 20 are values you want to verify too, change 2-19 to 1-20.


-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Marek Kilimajer
Zouari Fourat wrote:
here's the problem :
my user MUST input only digits between 1 and 20
doing a is_numeric and some comparaison can be bypassed by inputing :
.5
or
0.5
or
5.1
or
0.3
or
.01
...
...
so i thought that the smartest way is to use regex
if( $i = 1  $i = 20  $i == (int)$i) ...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions ?

2005-01-27 Thread Zouari Fourat
 if (preg_match(/[2-19]/,$x))
   echo It is!;

doesnt work !
this is working fine :
if (eregi(^-?([1-3])+$,$x)
 echo x is 1 or 2 or 3;



On Thu, 27 Jan 2005 08:42:19 -0700, Leif Gregory [EMAIL PROTECTED] wrote:
 Hello Zouari,
 
 Thursday, January 27, 2005, 7:33:04 AM, you wrote:
 Z I need to verify if $x is between 1 and 20 and i need to do that
 Z with regular expressions ?
 
 If you *need* to do it with regexp, try this:
 
 
 
 if (preg_match(/[2-19]/,$x))
   echo It is!;
 
 
 
 If 1 and 20 are values you want to verify too, change 2-19 to 1-20.
 
 --
 Leif (TB lists moderator and fellow end user).
 
 Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
 Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB
 
 --
 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] regular expressions ?

2005-01-27 Thread Zouari Fourat
 this is working fine :
 if (eregi(^-?([1-3])+$,$x)
  echo x is 1 or 2 or 3;

i forgot to say that doesnt work with 1-20 :(
how to do it ?


On Thu, 27 Jan 2005 16:53:55 +0100, Zouari Fourat [EMAIL PROTECTED] wrote:
  if (preg_match(/[2-19]/,$x))
echo It is!;
 
 doesnt work !
 this is working fine :
 if (eregi(^-?([1-3])+$,$x)
  echo x is 1 or 2 or 3;
 
 
 On Thu, 27 Jan 2005 08:42:19 -0700, Leif Gregory [EMAIL PROTECTED] wrote:
  Hello Zouari,
 
  Thursday, January 27, 2005, 7:33:04 AM, you wrote:
  Z I need to verify if $x is between 1 and 20 and i need to do that
  Z with regular expressions ?
 
  If you *need* to do it with regexp, try this:
 
  
 
  if (preg_match(/[2-19]/,$x))
echo It is!;
 
  
 
  If 1 and 20 are values you want to verify too, change 2-19 to 1-20.
 
  --
  Leif (TB lists moderator and fellow end user).
 
  Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
  Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB
 
  --
  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] regular expressions ?

2005-01-27 Thread Zouari Fourat
to Marek Kilimajer :
$i='5.';
if (($i=1)  ($i=20)  ($i==(int)$i))
echo 'yes';

// yes
:'(



On Thu, 27 Jan 2005 16:52:20 +0100, Marek Kilimajer [EMAIL PROTECTED] wrote:
 Zouari Fourat wrote:
  here's the problem :
  my user MUST input only digits between 1 and 20
  doing a is_numeric and some comparaison can be bypassed by inputing :
 
  .5
  or
  0.5
  or
  5.1
  or
  0.3
  or
  .01
  ...
  ...
 
  so i thought that the smartest way is to use regex
 
 
 if( $i = 1  $i = 20  $i == (int)$i) ...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Marek Kilimajer
Zouari Fourat wrote:
to Marek Kilimajer :
$i='5.';
if (($i=1)  ($i=20)  ($i==(int)$i))
echo 'yes';
// yes
:'(
ok, then use regexp:
if (($i=1)  ($i=20)  regexp('^[0-9]+$', $i))
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions ?

2005-01-27 Thread Robin Vickery
On Thu, 27 Jan 2005 16:56:05 +0100, Zouari Fourat [EMAIL PROTECTED] wrote:
  this is working fine :
  if (eregi(^-?([1-3])+$,$x)
   echo x is 1 or 2 or 3;
 
 i forgot to say that doesnt work with 1-20 :(
 how to do it ?

You're far better off doing it arithmetically as someone already said,
however  if you absolutely *have* to use a regexp then this is how you
go about it:

You need to match these possible variations:
1. the number '20'
2. the number '1' followed by any digit between 0 and 9.
3. any digit between 1 and 9.

the pattern for the first one is easy. it's just a fixed string: 20
the pattern for the second is only slightly harder: 1[0-9]
the pattern for the third is: [1-9]

You want to match any of them, so you join them together with an
alternation operator, the '|' symbol to get: 20|1[0-9]|[1-9]

This will match any string that contains the numbers 1-20, such as
'200'. To make sure it only matches exactly the numbers you're
interested in, you have to anchor the start and finish ending up
with this:

if (preg_match('/^(20|1[0-9]|1-9])$/', $candidate)) {
   // $candidate is a decimal integer between 1 and 20 inclusive with
no leading zeros.
}

 -robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Zouari Fourat
Robin : 
$i='2';
if (preg_match('/^(20|1[0-9]|1-9])$/', $i)) {
echo 'yes';
}else
echo 'no';


stdout: no

Marek :
$i='02';
if (($i=1)  ($i=20)  (eregi('^[0-9]+$', $i)))
echo 'yes';


stdout: yes

i hate reposting but my problem seems to persist :( sorry.


On Thu, 27 Jan 2005 16:28:37 +, Robin Vickery [EMAIL PROTECTED] wrote:
 On Thu, 27 Jan 2005 16:56:05 +0100, Zouari Fourat [EMAIL PROTECTED] wrote:
   this is working fine :
   if (eregi(^-?([1-3])+$,$x)
echo x is 1 or 2 or 3;
 
  i forgot to say that doesnt work with 1-20 :(
  how to do it ?
 
 You're far better off doing it arithmetically as someone already said,
 however  if you absolutely *have* to use a regexp then this is how you
 go about it:
 
 You need to match these possible variations:
 1. the number '20'
 2. the number '1' followed by any digit between 0 and 9.
 3. any digit between 1 and 9.
 
 the pattern for the first one is easy. it's just a fixed string: 20
 the pattern for the second is only slightly harder: 1[0-9]
 the pattern for the third is: [1-9]
 
 You want to match any of them, so you join them together with an
 alternation operator, the '|' symbol to get: 20|1[0-9]|[1-9]
 
 This will match any string that contains the numbers 1-20, such as
 '200'. To make sure it only matches exactly the numbers you're
 interested in, you have to anchor the start and finish ending up
 with this:
 
 if (preg_match('/^(20|1[0-9]|1-9])$/', $candidate)) {
// $candidate is a decimal integer between 1 and 20 inclusive with
 no leading zeros.
 }
 
  -robin
 
 --
 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] regular expressions ?

2005-01-27 Thread John Nichel
Zouari Fourat wrote:
Robin : 
	$i='2';
	if (preg_match('/^(20|1[0-9]|1-9])$/', $i)) {
Open the bracket for the last parameter...
/^(20|1[0-9]|[1-9])$/
-^
--
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] regular expressions ?

2005-01-27 Thread Leif Gregory
Hello Zouari,

Thursday, January 27, 2005, 8:53:55 AM, you wrote:
Z doesnt work !
Z this is working fine :
Z if (eregi(^-?([1-3])+$,$x)
Z  echo x is 1 or 2 or 3;

Whoops. Sorry.. That's what I get for throwing out an answer while on
the run:

Try this:

?php

for ($x=0; $x  120; $x++)
{
  if (preg_match(/^([1-9]{1}|1[0-9]{1}|20)$/,$x))
echo It is!  . $i . br;
  else
echo It's not! . $i . br;
}

?

The for loop is just for show.


-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions ?

2005-01-27 Thread Richard Lynch
Zouari Fourat wrote:
 Robin :
   $i='2';
   if (preg_match('/^(20|1[0-9]|1-9])$/', $i)) {

You are missing a [ before the 1-9 in after the last |

The regex WILL work if you type it correctly :-)

-- 
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] regular expressions ?

2005-01-27 Thread Rick Fletcher
Robin Vickery wrote:
On Thu, 27 Jan 2005 16:56:05 +0100, Zouari Fourat [EMAIL PROTECTED] wrote:
this is working fine :
if (eregi(^-?([1-3])+$,$x)
echo x is 1 or 2 or 3;
i forgot to say that doesnt work with 1-20 :(
how to do it ?

if (preg_match('/^(20|1[0-9]|1-9])$/', $candidate)) {
   // $candidate is a decimal integer between 1 and 20 inclusive with
no leading zeros.
}
/^(1?[1-9]|[12]0)$/ works too.  The first part covers 1-9, 11-19; the 
second part gets you 10 and 20.

Plus, it's ever so slightly shorter!  And isnt' that what's most 
important? :P

--Rick
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expressions ?

2005-01-27 Thread Leif Gregory
Hello Rick,

Thursday, January 27, 2005, 12:36:39 PM, you wrote:
R /^(1?[1-9]|[12]0)$/ works too. The first part covers 1-9, 11-19;
R the second part gets you 10 and 20.

R Plus, it's ever so slightly shorter! And isnt' that what's most
R important? :P


Purty  :grin:


-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions Q

2004-10-28 Thread Alex Hogan
 ereg((([[:blank:]+]|^)[09][0-9][4789][0][0-9]{3}[abcABC]?),$zn[1],$zaakn
 ummers1);
 
 I thought that ereg would get all of them and store them in the array
 $zaaknummers1 however this is not the case

I just asked a question similar to this the other day.
Try using;

preg_match_all((([[:blank:]+]|^)[09][0-9][4789][0][0-9]{3}[abcABC]?),
$zn[1], $zaaknummers1);




alex hogan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regular expressions Q

2004-10-28 Thread Jack . van . Zanen
Thx,


Just joined today, should have looked thru the archives first though.

Jack

-Original Message-
From: Alex Hogan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 28, 2004 3:31 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Regular expressions Q


 ereg((([[:blank:]+]|^)[09][0-9][4789][0][0-9]{3}[abcABC]?),$zn[1],
 $zaakn
 ummers1);
 
 I thought that ereg would get all of them and store them in the array 
 $zaaknummers1 however this is not the case

I just asked a question similar to this the other day.
Try using;

preg_match_all((([[:blank:]+]|^)[09][0-9][4789][0][0-9]{3}[abcABC]?),
$zn[1], $zaaknummers1);




alex hogan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2004-07-15 Thread Marek Kilimajer
Arik Raffael Funke wrote:
Hello together,
I am havin trouble with php regular expressions. I would like to
implement following pattern Last Name:\s*(.*)\n.
- From following text,
Name: James
Last Name: Jason
Street: abc
I get just 'Jason'. But what I currently get is:
Jason
Street: abc
Obviously the new-line is missed. Any thoughts on this?
sample code:
ereg(Last Name:\s*(.*)\n, $strInput, $regs)
echo $regs[1];
Thanks for the help!
Cheers,
Arik
Donno about regular expressions but with perl compatible you can use:
preg_match('/Last Name:\s*(.*)\n/', $inputStr, $regs);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expressions

2004-07-15 Thread Matt M.
 Obviously the new-line is missed. Any thoughts on this?
 
 sample code:
 ereg(Last Name:\s*(.*)\n, $strInput, $regs)
 echo $regs[1];

try this:

ereg(Last Name:\s*(.*[^\n]), $strInput, $regs);
echo $regs[1];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2004-07-15 Thread Arik Raffael Funke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, 15 Jul 2004 08:02:13 -0500
Matt M. [EMAIL PROTECTED] wrote:

  Obviously the new-line is missed. Any thoughts on this?
  
  sample code:
  ereg(Last Name:\s*(.*)\n, $strInput, $regs)
  echo $regs[1];
 
 try this:
 
 ereg(Last Name:\s*(.*[^\n]), $strInput, $regs);
 echo $regs[1];
 

Thanks for the quick help.

Both ways,
preg_match('/Last Name:\s*(.*)\n/', $inputStr, $regs);
and
ereg(Last Name:\s*(.*[^\n]), $strInput, $regs);
work fine.

However if I have,
Last Name:
Street: Teststreet
(no entry after last name)

Both search strings return me:
- 

Street: Teststreet
- 

Also why doesn't Last Name:\s*(.*)$ work, and neither ^Last
Name:\s*(.*). Both strings are not found at all - that's why I thought
the php implementation might treat new lines in a strange way.

Can anybody explain these effects to me?

Cheers,
Arik
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFA9oN1//PXyz2NiW8RAmCQAJ9wRDxc8YDyfU+4EoNeRsqMKJDPBQCgsMvv
7cpFD6cYZuckqGdY+1Gtqi8=
=Hi/P
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions

2004-07-15 Thread Jason Wong
On Thursday 15 July 2004 21:15, Arik Raffael Funke wrote:

 However if I have,
 Last Name:
 Street: Teststreet
 (no entry after last name)

 Both search strings return me:
 

 Street: Teststreet
 

 Also why doesn't Last Name:\s*(.*)$ work, and neither ^Last
 Name:\s*(.*). Both strings are not found at all - that's why I thought
 the php implementation might treat new lines in a strange way.

  preg_match('|^Last Name:(.*)$|m', $haystack, $matches);

should work.

-- 
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
--
/*
Someone is speaking well of you.

How unusual!
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions Tester/designer

2004-06-20 Thread Tom Rogers
Hi,

Sunday, June 20, 2004, 7:23:53 AM, you wrote:
A Anyone know of a good regular expressions tester/designer for php coding
A running  windows.

A I've looked at the Rad Software Regular Expressions Designer and it
A looks pretty good except that it is intended for .net and it really
A doesn't seem to be entirely PCRE compatible.

A Thanks


This works with perl regular expressions

http://weitz.de/files/regex-coach.exe

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions Tester/designer

2004-06-20 Thread Ulrik S. Kofod

Tom Rogers sagde:


 This works with perl regular expressions

 http://weitz.de/files/regex-coach.exe


Thanks! Great tool! I really needed something like that.
It just seems like it can't handle $1,  $2 ...$x in the replacement string?
Isn't there a way to make that work ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expressions Tester/designer

2004-06-19 Thread Joel Kitching
On Sat, 19 Jun 2004 17:23:53 -0400, Al [EMAIL PROTECTED] wrote:
 
 Anyone know of a good regular expressions tester/designer for php coding
 running  windows.
 
 I've looked at the Rad Software Regular Expressions Designer and it
 looks pretty good except that it is intended for .net and it really
 doesn't seem to be entirely PCRE compatible.
 
 Thanks
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

You could always just use a simple online one like...

http://www.quanetic.com/regex.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] regular expressions php/perl/actionscript

2004-04-22 Thread Chris W. Parker
Gabino Travassos mailto:[EMAIL PROTECTED]
on Thursday, April 22, 2004 12:24 PM said:

 I'm wondering if Regular Expressions are the same in Perl and PHP (and
 possibly Actionscript)? They look the same and smell the same, but if
 I see a book in a store for Perl Regular Expressions that's $10
 cheaper than the PHP one (is there one?), then is it the same thing?

i'd get the perl book over the php book personally. but then again i'm
pretty sure there is not a perl regex book, nor is there a php regex
book. there's probably just a regex book. you as the user have to decide
what works where.

this page will tell you what php supports:

http://us3.php.net/ereg

 While we're on this topic, I'm looking to find an attribute in an XML
 and replace it with a string variable I get from a form.

check the other functions on that page. your answer is there!



chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions php/perl/actionscript

2004-04-22 Thread John W. Holmes
From: Gabino Travassos [EMAIL PROTECTED]

 I'm wondering if Regular Expressions are the same in Perl and PHP (and
 possibly Actionscript)? They look the same and smell the same, but if I
see
 a book in a store for Perl Regular Expressions that's $10 cheaper than the
 PHP one (is there one?), then is it the same thing?

The regular expressions used in the preg_* functions closely resembles
Perl. The basic syntax is the same. The regular expressions used in the
ereg_* functions are POSIX-Extended.

http://us2.php.net/manual/en/ref.pcre.php (Perl-compatible)
http://us2.php.net/manual/en/ref.regex.php (POSIX Extended)

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regular expressions php/perl/actionscript

2004-04-22 Thread Gabino Travassos
I forgot to mention that in my XML file, inside the quotes in this attribute
 backColour=xx  the x's will be variable..., so I need some kind of
wildcard to select everything from backColour + the next 8 or 9
characters, cuz it might be backColour=333990 or whatnot.

'backColour' will be a unique string in the XML file, but I'll have those
quotes and a variable RGB hex value to find and replace.

Can I do something like
$bgClrOld = ereg_match('/backColour/'+8chr,$s);
?

Merci

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   >