Re: [PHP] Regular Expression help

2006-01-19 Thread John Nichel

Chris wrote:
snip

preg_replace('/(?!^)([A-Z])/','_$1','JimJoeBobBriggs');


Ohhhregex-fu black belt.  ;)

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] regular expression for integer range

2005-09-08 Thread Mark Rees
Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  Hi all,
 
 
  I want to write regular expression for checking the string format
entered
  by user.
 
  the allowed formats are
 
  examples:
  10
  10,
  10,12-10
  12-10
 
  that is the valid strings are:
  1. only integer
  2. an integer, range of integers example 3
 
  and no other characters must be allowed.

You could simplify the matter by replacing all - and , with, say, 0 and
then using the simple \d+ (I think) regexp.


 Hi babu,

 As you've pointed out, you have 4 distinct scenarios to deal with, and it
 may be very difficult, without a great deal of tuning and tweaking, to
 define a regular expression that can effectively match all 4 scenarios
 without including false matches as well.

 One way of dealing with this is to build more specialized and exact
regular
 expressions for each possible scenario and group them together in an if
 statement.

 Eg.

 if (preg_match('/^\d+$/',$subject) || preg_match('/^\d+,$/',$subject) ||
 preg_match('/^\d+,\d+-\d+$/', $subject) || etc etc){

 // code for successful match of valid data in $subject

 } else {

 // code for invalid data in $subject

 }

 Basically, the if/else statement is testing each distinct possible pattern
 and executing code if any of those distinct possible patterns match.

 It may not ultimately be the most graceful way of dealing with the
 situation, but having spent many hours attempting to tweak complex regular
 expressions looking for the magic combination, I've learned that breaking
 scenarios down this way can save a lot of development time and
frustration.
 This doesn't mean there isn't a benefit to finding the perfect regular
 expression for your needs, just that it can often be difficult to
guarantee
 your code won't be plagued by false matches or false exclusions as your
 expression becomes more and more complex.

 Hope this helps a little.

 Much warmth,

 Murray
 ---
 Lost in thought...
 http://www.planetthoughtful.org

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



Re: [PHP] regular expression for integer range

2005-09-07 Thread Robin Vickery
On 9/6/05, babu [EMAIL PROTECTED] wrote:
 Hi all,
 
 
 I want to write regular expression for checking the string format entered by 
 user.
 
 the allowed formats are
 
 examples:
 10
 10,
 10,12-10
 12-10
 
 that is the valid strings are:
 1. only integer
 2. an integer, range of integers example 3
 
 and no other characters must be allowed.

$re = '/^(\d+)(,\d+-\d+)?$/';
preg_match($re, $value);

This only allows
 * an integer or
 * an integer followed by a comma and a range of integers

It doesn't allow anything else - even whitespace after the comma.

 -robin

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



RE: [PHP] regular expression for integer range

2005-09-07 Thread Murray @ PlanetThoughtful
 Hi all,
 
 
 I want to write regular expression for checking the string format entered
 by user.
 
 the allowed formats are
 
 examples:
 10
 10,
 10,12-10
 12-10
 
 that is the valid strings are:
 1. only integer
 2. an integer, range of integers example 3
 
 and no other characters must be allowed.

Hi babu,

As you've pointed out, you have 4 distinct scenarios to deal with, and it
may be very difficult, without a great deal of tuning and tweaking, to
define a regular expression that can effectively match all 4 scenarios
without including false matches as well.

One way of dealing with this is to build more specialized and exact regular
expressions for each possible scenario and group them together in an if
statement.

Eg.

if (preg_match('/^\d+$/',$subject) || preg_match('/^\d+,$/',$subject) ||
preg_match('/^\d+,\d+-\d+$/', $subject) || etc etc){

// code for successful match of valid data in $subject

} else {

// code for invalid data in $subject

}

Basically, the if/else statement is testing each distinct possible pattern
and executing code if any of those distinct possible patterns match.

It may not ultimately be the most graceful way of dealing with the
situation, but having spent many hours attempting to tweak complex regular
expressions looking for the magic combination, I've learned that breaking
scenarios down this way can save a lot of development time and frustration.
This doesn't mean there isn't a benefit to finding the perfect regular
expression for your needs, just that it can often be difficult to guarantee
your code won't be plagued by false matches or false exclusions as your
expression becomes more and more complex.

Hope this helps a little.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



Re: [PHP] regular expression for integer range

2005-09-06 Thread Philip Hallstrom




On Tue, 6 Sep 2005, babu wrote:


Hi all,


I want to write regular expression for checking the string format entered by 
user.

the allowed formats are

examples:
10
10,
10,12-10
12-10

that is the valid strings are:
1. only integer
2. an integer, range of integers example 3

and no other characters must be allowed.


ereg(^[-0-9,]+$...

would do it, but it would also allow 10,- as a valid expression as 
well.. so if you want to check for valid ranges you'll want to beef that 
up a bit...


-philip

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



Re: [PHP] regular expression for integer range

2005-09-06 Thread John Nichel

babu wrote:

Hi all,
 
 
I want to write regular expression for checking the string format entered by user.
 
the allowed formats are
 
examples:

10
10,
10,12-10
12-10
 
that is the valid strings are:

1. only integer
2. an integer, range of integers example 3
 
and no other characters must be allowed.


Crude, but it will work

preg_match ( /^[-0-9,]+$/, $value )

It will also match just dashes and/or just comma's with no numbers.

http://us2.php.net/manual/en/reference.pcre.pattern.syntax.php

--
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 expression for time

2005-08-29 Thread Leif Gregory
Hello babu,

Monday, August 29, 2005, 6:50:32 AM, you wrote:
 how can i write regular expression for time in 24-hour format i:e,
 HH:MM:SS. using preg_match.

?php
$xtime=19:59:53;
if (preg_match(/([01][0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9]/, $xtime))
  echo Good;
else
  echo Bad;
?


--TBUDL/BETA/DEV/TECH Lists Moderator / PGP 0x6C0AB16B
 __       Geocaching:http://gps.PCWize.com
(  )  ( ___)(_  _)( ___)  TBUDP Wiki Site:  http://www.PCWize.com/thebat/tbudp
 )(__  )__)  _)(_  )__)   Roguemoticons  Smileys:http://PCWize.com/thebat
()()()(__)PHP Tutorials and snippets:http://www.DevTek.org

Save your pennies.  The dollars go to the I.R.S.

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



Re: [PHP] Regular expression question

2005-08-12 Thread Robin Vickery
On 8/11/05, Leon Vismer [EMAIL PROTECTED] wrote:
 Hi Robin
 
 Many thanks for this,
 
 how would one extend this to support the following:
 $str = insert into userComment (userID, userName, userSurname) values (0,
 'Leon', 'mcDonald');
 
 one does not want
 
 $str = insert into user_comment (user_id, user_name, user_surname) values (0,
 'Leon', 'mc_donald');

$match  = '/(?=[a-z])(?![Mm]c|[Mm]ac)([A-Z]+)/e';

Should make exceptions for McDonald, mcDonald, MacDonald and macDonald. 

With luck you don't have any tables called something like appleMacUsers.

 unfortunately lookbehind assertions does not support non-fixed length chars so
 /(?=(?!')[a-z])([A-Z]+)/e will work for 'mDonald' but the following will not
 work.

True, lookbehind assertions must be a fixed length - but unlike in
perl, they can have alternates which are different fixed lengths:

This is illegal, because the length isn't fixed:  (?![Mm]a?c) 

This is fine, because each alternate is fixed even though they are
diffferent lengths: (?![Mm]c|[Mm]ac)

 -robin

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



Re: [PHP] Regular expression question

2005-08-11 Thread b-bonini
n Thu, 11 Aug 2005, Leon Vismer wrote:

 Hi

 I would like to convert from one naming convention within a sql statement to
 another.

 I have the following,

 code
 $str = insert into userComment (userID, userName, userSurname) values (0,
 'Leon', 'Vismer');

 $match = array(
 /([a-z]+)(ID)/,
 /([a-z]+)([A-Z])/
 );

 $replace = array(
 \$1_id,
 \$1_\$2
 );

 $nstr = preg_replace($match, $replace, $str);
 echo $nstr .\n;
 /code


 the above gets me to
 insert into user_Comment (user_id, user_Name, user_Surname) values (0, 'Leon',
 'Vismer')

 however I want to get to

 insert into user_comment (user_id, user_name, user_surname) values (0, 'Leon',
 'Vismer')

 Some help from the regex experts ;-)


Just a quick note; why dont' you search on user since it's the constant and 
replace 'user[A-Z]' with 'user_[a-z]' or in the case of userID 'user[A-Z]{2}'

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



Re: [PHP] Regular expression question

2005-08-11 Thread Leon Vismer
Hi

 Just a quick note; why dont' you search on user since it's the constant
 and replace 'user[A-Z]' with 'user_[a-z]' or in the case of userID
 'user[A-Z]{2}'

This is part of my problem user will not always be constant, I basically want 
to be able to change between two naming conventions.

Example:

userID becomes user_id
clientID becomes client_id
tableName becomes table_name
anotherTableName becomes another_table_name
etc.

Thanks
--
Leon

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



Re: [PHP] Regular expression question

2005-08-11 Thread Robin Vickery
On 8/11/05, Leon Vismer [EMAIL PROTECTED] wrote:
 Hi
 
 I would like to convert from one naming convention within a sql statement to
 another.
 
 I have the following,
 
 code
 $str = insert into userComment (userID, userName, userSurname) values (0,
 'Leon', 'Vismer');
 
 $match = array(
 /([a-z]+)(ID)/,
 /([a-z]+)([A-Z])/
 );
 
 $replace = array(
 \$1_id,
 \$1_\$2
 );

?php
$str = insert into userComment (userID, userName, userSurname) values
(0, 'Leon', 'Vismer');

$match  = '/(?=[a-z])([A-Z]+)/e';
$replace = 'strtolower(_$1)';
print preg_replace($match, $replace, $str);
?

insert into user_comment (user_id, user_name, user_surname) values (0,
'Leon', 'Vismer')

 -robin

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



Re: [PHP] Regular expression question

2005-08-11 Thread Leon Vismer
Hi Robin

Many thanks for this,

how would one extend this to support the following:
$str = insert into userComment (userID, userName, userSurname) values (0, 
'Leon', 'mcDonald');

one does not want

$str = insert into user_comment (user_id, user_name, user_surname) values (0, 
'Leon', 'mc_donald');

unfortunately lookbehind assertions does not support non-fixed length chars so
/(?=(?!')[a-z])([A-Z]+)/e will work for 'mDonald' but the following will not 
work.

/(?=(?!')([a-z]+))([A-Z]+)/e

Any ideas?

Many thanks
--
Leon

 ?php
 $str = insert into userComment (userID, userName, userSurname) values
 (0, 'Leon', 'Vismer');

 $match  = '/(?=[a-z])([A-Z]+)/e';
 $replace = 'strtolower(_$1)';
 print preg_replace($match, $replace, $str);
 ?

 insert into user_comment (user_id, user_name, user_surname) values (0,
 'Leon', 'Vismer')

  -robin

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



Re: [PHP] Regular expression help

2005-08-02 Thread John Nichel

David Christensen wrote:

I just plain suck at regex, so I was hoping to get some hints from you
regex experts out there.  I'm sure it's been done a thousand times, but
I can't seem to find what I'm looking for with a simple google search:

$phone could be 1234567890 OR
$phone could be 123-456-7890 OR
$phone could be (123) 456 7890 OR
$phone could have other unexpected characters in it, even control
characters.

So what I'm desiring to do is run some type of regex on $phone and only
return the integers and assign the cleaned string back to $phone.  I
thought I knew how to do this, but it's not working.

Thanks for your guidance.



If all you want is the digits

$phone = preg_replace ( /\D/, , $phone );

Same as

/[^0-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 Expression to replace pseudo-HTML?

2005-04-21 Thread Philip Hallstrom
I'm hoping someone can help me figure out a regex that will replace
pseudo-HTML codes in a string with desired HTML equivalents. In particular,
I'm trying to implement a message quoting facility, such as when you click
on the 'quote'  button in phpBB.
http://us2.php.net/manual/en/function.preg-replace.php
There's an example part way down the page that's almost exactly what you 
want...

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


Re: [PHP] Regular expression. What is wrong?

2005-02-14 Thread Richard Lynch
Kostyantyn Shakhov wrote:
 I have to check the phone number. I use some regular expression for
 this. The phone number can contain only numbers and characters like
 +,-,),( and space. The problem is when I use a Perl-style all works as
 intended but when I use a Posix-style I've got the Warning: ereg():
 REG_ERANGE and the result is opposite to intended one. What is wrong
 in the following?

  ?php
$test_phone = 8 (044) 419-0567;

if(preg_match(/^[+]?[\d\-\040\)\(]+$/, $test_phone))

For starters, those \ characters are probably not doing what you think...

\ is special in PHP inside quotes (and apostrophes)
\ is also special to preg_match.

While \d might be fine today, because \d isn't a special combination to
PHP, you'd be safer to write \\d so that PHP will ALWAYS send \d to the
preg engine.

{
  echo valid phonebr /;
}
else
{
  echo not valid phonebr /;
}

if(ereg(^[+]?[0-9\-[:space:]\)\(]+$, $test_phone))

Here, the \- is out of whack.

If you want a literal - to be valid, put it at the end of your character
class [0-9-] for example, allows 0-9 and the '-'
[a-zA-Z0-9-] allows alphanumeric and the '-'

I don't think \- is kosher, though, which is your REG_ERANGE error.

You may want to check out Regex Coach -- a program that lets you try out
Regular Expressions and see them in action so to speak.

{
  echo valid phonebr /;
}
else
{
  echo not valid phonebr /;
}
  ?

 --
 Best regards,
  Kostyantyn Shakhov mailto:[EMAIL PROTECTED]

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] regular expression help

2005-01-21 Thread Jason Wong
On Saturday 22 January 2005 00:12, Jason wrote:
 Simple functions to check  fix if necessary invalid formating of a MAC
 address... I seem to be having problems with the global variable $mac
 not being returned from the fix_mac() function.  Any help is appreciated.

Your subject says regular expression help but your problem is with the 
global variable $mac  So which is it? If you're going to declare a 
variable as 'global' then it has to be done in every function in which that 
variable is to be used.

Which means here:

 function chk_mac( $mac ) {
   if( eregi(
 ^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-
f]{2}\:[0-9A-Fa-f]{2}$, $mac ) ) {
return 0;
   } else {
return 1;
   }
 }

and wherever else.

-- 
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 expression help

2005-01-21 Thread Bret Hughes
On Fri, 2005-01-21 at 10:12, Jason wrote:
 Simple functions to check  fix if necessary invalid formating of a MAC 
 address... I seem to be having problems with the global variable $mac 
 not being returned from the fix_mac() function.  Any help is appreciated.
 
 ?php
 /*
   * ex. 00:AA:11:BB:22:CC
   */
 function chk_mac( $mac ) {
   if( eregi( 
 ^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$,
  
 $mac ) ) {
return 0;
   } else {
return 1;
   }
 }
 
 /*
   * check validity of MAC  do replacements if necessary
   */
 function fix_mac( $mac ) {
   global $mac;
   /* strip the dash  replace with a colon */
   if( eregi( 
 ^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$,
  
 $mac ) ) {
$mac = preg_replace( /\-/, :, $mac );
return $mac;
   }
   /* add a colon for every two characters */
   if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {
/* split up the MAC and assign new var names */
@list( $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = @str_split( $mac, 
 2 );
/* put it back together with the required colons */
$mac = $mac1 . : . $mac2 . : . $mac3 . : . $mac4 . : . $mac5 
 . : . $mac6;
return $mac;
   }
 }
 
 // do our checks to make sure we are using these damn things right
 $mac1 = 00aa11bb22cc;
 $mac2 = 00-aa-11-bb-22-cc;
 $mac3 = 00:aa:11:bb:22:cc;
 
 // make sure it is global
 global $mac;
 

if you want to use globals you need to use the global in the function
not the main body.

afaict you don't need globals at all you pass mac1 to each function and
use it as $mac in the function (exactly what you want to do) and return
local $mac to $mac in the main body.  perfectly legal.  If you set mac
to global in the function I suspect that you end up not using  the local
mac and are testing an empty var in the first pass of fix_mac.

remove the global statements and you are well on your way.

Bret

 // if mac submitted is invalid check  fix if necessary
 if( chk_mac( $mac1 ) != 0 ) {
   $mac = fix_mac( $mac1 ); echo $mac1 .  converted to  . $mac . br;
 }
 if( chk_mac( $mac2 ) != 0 ) {
   $mac = fix_mac( $mac2 ); echo $mac2 .  converted to  . $mac . br;
 }
 if( chk_mac( $mac3 ) != 0 ) {
   $mac = fix_mac( $mac3 ); echo $mac3 .  converted to  . $mac . br;
 }
 
 ?
 -- 
 Jason Gerfen
 
 And remember... If the ladies
   don't find you handsome, they
   should at least find you handy...
   ~The Red Green show
 
 -- 
 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 expression help

2005-01-21 Thread Richard Lynch
Jason wrote:
 Simple functions to check  fix if necessary invalid formating of a MAC
 address... I seem to be having problems with the global variable $mac
 not being returned from the fix_mac() function.  Any help is appreciated.
 function fix_mac( $mac ) {
   global $mac;

It's really weird to both pass in $mac as an argument and to declare it
global...

Do one or the other, but not both.

Can't help you with the mess of Regex you've got though...

-- 
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 expression help

2005-01-21 Thread Jochem Maas
Richard Lynch wrote:
Jason wrote:
Simple functions to check  fix if necessary invalid formating of a MAC
address... I seem to be having problems with the global variable $mac
not being returned from the fix_mac() function.  Any help is appreciated.
function fix_mac( $mac ) {
 global $mac;

It's really weird to both pass in $mac as an argument and to declare it
global...
Do one or the other, but not both.
quite.
Can't help you with the mess of Regex you've got though...
now I bet you can actually, chicken and egg: you have to have the skill 
to recognise the mess. ;-)

Jason - don't be dishearted:
a, regexp are/can be hard
b, anyone who is giving them a go, is probably trying hard to improve
their skills (we like that :-)) - regexps are quite a hurdle for most 
people.
c, we all start out writing regexps like yours (i.e. simple ones) and 
eventually they become more and more complex/arcane until you become 
Larry Wall.

---
did someone say 'who is Larry Wall?'?, 10 lashes for that man

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


Re: [PHP] Regular Expression for a UK Mobile

2004-10-15 Thread Gareth Williams
Do you even need a regex?
What about
if (strlen($_POST['mobile_number']) != 11  
substr($_POST['mobile_number'],0,3) != 447)
{
	$error=Invalid Number;
}

On 15 Oct 2004, at 13:38, Shaun wrote:
Hi,
Could anyone help me with a reugular expression for a UK mobile phone
number?
So far I have tried this but with no success
snip
$regexp = /^447[0-9]{9}$/;
if(!preg_match( $regexp, $_POST[mobile_number] )){
 $error = Invalid Mobile Number;
/snip
The number nust be 11 numbers long, be all numbers, have no spaces and 
begin
with 447.

Any help would be greatly appreciated...
--
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 Expression for a UK Mobile

2004-10-15 Thread Robert Cummings
On Fri, 2004-10-15 at 07:45, Gareth Williams wrote:
 Do you even need a regex?
 
 What about
 
 if (strlen($_POST['mobile_number']) != 11  
 substr($_POST['mobile_number'],0,3) != 447)
 {
   $error=Invalid Number;
 }

This doesn't verify that the portion following 447 is also a number.

eg. 4474567X901

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Regular Expression for a UK Mobile

2004-10-15 Thread Jason Wong
On Friday 15 October 2004 19:38, Shaun wrote:

 Could anyone help me with a reugular expression for a UK mobile phone
 number?

 So far I have tried this but with no success

 snip
 $regexp = /^447[0-9]{9}$/;
 if(!preg_match( $regexp, $_POST[mobile_number] )){
  $error = Invalid Mobile Number;
 /snip

 The number nust be 11 numbers long, be all numbers, have no spaces and
 begin with 447.

11 minus 3 = 8?

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
When nothing can possibly go wrong, it will.
*/

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



Re: [PHP] Regular Expression for a UK Mobile

2004-10-15 Thread John Nichel
Shaun wrote:
Hi,
Could anyone help me with a reugular expression for a UK mobile phone 
number?

So far I have tried this but with no success
snip
$regexp = /^447[0-9]{9}$/;
if(!preg_match( $regexp, $_POST[mobile_number] )){
 $error = Invalid Mobile Number;
/snip
The number nust be 11 numbers long, be all numbers, have no spaces and begin 
with 447.
You're matching 447, then 9 numbers after that...bringing the total 
numbers to 12, not 11.

$regexp = /^447\d{8}$/;
--
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 Expression for a UK Mobile

2004-10-15 Thread Ford, Mike
To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm



On 15 October 2004 12:39, Shaun wrote:

 Hi,
 
 Could anyone help me with a reugular expression for a UK mobile phone
 number? 
 
 So far I have tried this but with no success
 
 snip
 $regexp = /^447[0-9]{9}$/;

That expression looks perfectly valid for the conditions you have stated
(given that you meant 12 digits, not 11, which would be correct for UK
mobiles).  There must be some other kind of error.

As a first step, I suggest you do a var_dump($_POST['mobile_number']) to
make sure it's exactly what you think it should be.  (And, yes, you should
be quoting the index to the $_POST[] array.)

 if(!preg_match( $regexp, $_POST[mobile_number] )){
  $error = Invalid Mobile Number;
 /snip
 
 The number nust be 11 numbers long, be all numbers, have no
 spaces and begin
 with 447.

However, if you mean genuine mobiles, and not pagers or other follow-me type
numbers in the UK 07 range (or even completely unallocated parts of it!),
then you need to refine that pattern a bit; this should do:

   $regexp = /^447[7-9][0-9]{8}$/;

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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



Re: [PHP] Regular Expression for a UK Mobile

2004-10-15 Thread Chris Dowell
Try is_int($_POST['mobile_number']) or ctype_digit($_POST['mobile_number'])
HTH
Cheers
Chris
Robert Cummings wrote:
On Fri, 2004-10-15 at 07:45, Gareth Williams wrote:
Do you even need a regex?
What about
if (strlen($_POST['mobile_number']) != 11  
substr($_POST['mobile_number'],0,3) != 447)
{
	$error=Invalid Number;
}

This doesn't verify that the portion following 447 is also a number.
   eg. 4474567X901
Cheers,
Rob.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression for a UK Mobile

2004-10-15 Thread Gareth Williams
You could add is_integer() into the if statement.
On 15 Oct 2004, at 14:07, Robert Cummings wrote:
On Fri, 2004-10-15 at 07:45, Gareth Williams wrote:
Do you even need a regex?
What about
if (strlen($_POST['mobile_number']) != 11 
substr($_POST['mobile_number'],0,3) != 447)
{
$error=Invalid Number;
}
This doesn't verify that the portion following 447 is also a number.
eg. 4474567X901
Cheers,
Rob.
--
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression - highlighting

2004-10-07 Thread Aidan Lister
Hi Michael,

Thanks very much for the assistance, I'll have to investigate further!

Kind Regards,
Aidan Lister


Michael Sims [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Aidan Lister wrote:
 Hello list,

 I'm pretty terrible with regular expressions, I was wondering if
 someone would be able to help me with this
 http://paste.phpfi.com/31964

 The problem is detailed in the above link. Basically I need to match
 the contents of any HTML tag, except a link. I'm pretty sure a
 lookbehind set is needed in the center (%s) bit.

 Any suggestions would be appreciated, but it's not quite as simple as
 it sounds - if possible please make sure you run the above script and
 see if it PASSED.

 So basically, you want to put a link around foo, only if it doesn't
 already have one, right?

 The problem with look-behind assertions is that they have to be 
 fixed-width.
 If you're certain of what kind of data you're going to be dealing with 
 then
 this may be sufficient.  For example, I came up with a regex that will 
 PASS
 your script but I doubt seriously that it'll be very useful to you as it
 would be easy to break it by coming up with various test cases.  For your
 single test case, however, this works:

 /(?!a href=foo)(?!a href=)(foo)/

 The problem is that HTML tags can be split across lines...they have have 
 any
 variable amount of whitespace within the tag...they can have other
 attributes (class, id, onClick), etc.  Since look behind assertions have 
 to
 be fixed width it'd be impossible (IMHO) to come up with a single regex 
 that
 would match all cases, unless the input data was uniform.  For example,
 stuff like

 a   href = foo ID=id1 class=redlink
 onClick=javascript:someFunction();foo/a

 and its infinite variants could not be trapped for with a single regex 
 since
 you cannot have an infinite number of fixed width look-behind assertions.
 If quantifying modifiers such as '*', '+', and '?' were allowed in
 look-behind assertions it would be possible, but they aren't (see man
 perlre).

 If your data is coming from unknown sources you'll probably have to use a
 full fledged HTML parser to pull out text that isn't already part of an 
 a
 tag.  I know there are several of these available for perl and I'm sure
 there are for PHP too but I'm unaware of them.

 Sorry if this isn't terribly helpful.  Maybe I'm overlooking something and
 someone else will point out a simple way to accomplish what you're trying 
 to
 do... 

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



Re: [PHP] Regular expression

2004-10-07 Thread Hans H. Anderson
Alawi,

You should get some sort of nothing to repeat error.  Try moving the * to a +
and putting it after the [0-9].  I'm not sure that the * is picking up anything,
because it's not preceded by anything.

It could be that your $html doesn't match quite right, too (tabs and newlines 
differ from $html to the regular expression).  So I tried this with success:

$html =EOB
TRTD bgColor=#e4e4e4PBtest:/B/P/TD
TDP98938/P/TD/TRTR
EOB;

preg_match_all(/TRTD bgColor=#e4e4e4PBtest:\/B\/P\/TD
TDP([0-9]*)\/P\/TD\/TRTR/,$html,$match);

print_r($match);


Hans

On Thu, 7 Oct 2004, Alawi Albaity wrote:

 How can I grap number written in specifec place in html 
 I try this : 
 preg_match_all(/ TR
   TD bgColor=#e4e4e4
 PBtest:\/B\/P\/TD
   TD
 P(*[0-9])\/P\/TD\/TR
 TR/,$html,$match);
 its not work
 How can I do that
 
 
 -- 
 Alawi Albaity
 Jeddah - KSA
 Mobile : +966506660442
 
 -- 
 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 expression

2004-10-07 Thread Greg Donald
On Thu, 7 Oct 2004 12:12:10 -0500 (CDT), Hans H. Anderson
[EMAIL PROTECTED] wrote:
 It could be that your $html doesn't match quite right, too (tabs and newlines
 differ from $html to the regular expression).  So I tried this with success:

The 's' modifier will assist with matching across newlines:

http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

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



RE: [PHP] Regular Expression - highlighting

2004-10-03 Thread Michael Sims
Aidan Lister wrote:
 Hello list,

 I'm pretty terrible with regular expressions, I was wondering if
 someone would be able to help me with this
 http://paste.phpfi.com/31964

 The problem is detailed in the above link. Basically I need to match
 the contents of any HTML tag, except a link. I'm pretty sure a
 lookbehind set is needed in the center (%s) bit.

 Any suggestions would be appreciated, but it's not quite as simple as
 it sounds - if possible please make sure you run the above script and
 see if it PASSED.

So basically, you want to put a link around foo, only if it doesn't
already have one, right?

The problem with look-behind assertions is that they have to be fixed-width.
If you're certain of what kind of data you're going to be dealing with then
this may be sufficient.  For example, I came up with a regex that will PASS
your script but I doubt seriously that it'll be very useful to you as it
would be easy to break it by coming up with various test cases.  For your
single test case, however, this works:

/(?!a href=foo)(?!a href=)(foo)/

The problem is that HTML tags can be split across lines...they have have any
variable amount of whitespace within the tag...they can have other
attributes (class, id, onClick), etc.  Since look behind assertions have to
be fixed width it'd be impossible (IMHO) to come up with a single regex that
would match all cases, unless the input data was uniform.  For example,
stuff like

a   href = foo ID=id1 class=redlink
onClick=javascript:someFunction();foo/a

and its infinite variants could not be trapped for with a single regex since
you cannot have an infinite number of fixed width look-behind assertions.
If quantifying modifiers such as '*', '+', and '?' were allowed in
look-behind assertions it would be possible, but they aren't (see man
perlre).

If your data is coming from unknown sources you'll probably have to use a
full fledged HTML parser to pull out text that isn't already part of an a
tag.  I know there are several of these available for perl and I'm sure
there are for PHP too but I'm unaware of them.

Sorry if this isn't terribly helpful.  Maybe I'm overlooking something and
someone else will point out a simple way to accomplish what you're trying to
do...

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



Re: [PHP] regular expression help

2004-09-29 Thread Petar Nedyalkov
On Wednesday 29 September 2004 08:46, Ed Lazor wrote:
 complain
 Today I discovered that my ISP can't upgrade to PHP 5.  They use Plesk for
 server Administration and PHP 5 apparently breaks Plesk.  Plesk says
 they'll make PHP 5 support available as soon as it starts coming default on
 RedHat Enterprise.
 /complain

 Unfortunately, I now have a bunch of scripts that require PHP 5.  I'd
 upgraded my beta server for testing and everything has been going so great
 that I went gungho.  Honestly, I tried to not too many of the new features,
 just so I could ease into it and do more testing.  I'm finding little
 differences that I didn't even realize I was taking advantage of.  For
 example, there are a lot of places in the code where I've done something
 like this:

 print Learn more about {$product-get_Title()}.br;

http://www.php.net/manual/en/function.preg-replace.php

$pattern = /\{\$(.+?)\}/i;
$replacement = \\.\$$1\.\;

Try this out ;-) I haven't tested it but it's the right direction ;-)


 I uploaded scripts like this to the production server for more testing and
 PHP4 flagged all of the code like this as parse errors.  I'm not sure, but
 now I'm stuck having to go through all of the code to change the coding
 style  my editor (Dreamweaver MX 2004) allows me to do a global search
 and replace using regular expressions.  I have no idea what regular
 expression I'd use for something like this.  Any recommendations?

 Thanks,

 Ed

-- 
Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)
-
Orbitel - the New Generation Telecom! See www.orbitel.bg.

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



RE: [PHP] regular expression help

2004-09-29 Thread Ed Lazor
Thanks to everyone who sent in patterns =)  They worked like a charm =)

 
 $pattern = /\{\$(.+?)\}/i;
 $replacement = \\.\$$1\.\;

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



Re: [PHP] regular expression help

2004-09-28 Thread Matthew Fonda
Howdy,

Regular expressions are a simple way of matching patters.
You can learn more about regular expressions in general here:
http://www.opengroup.org/onlinepubs/007908799/xbd/re.html

If you are interested in using regular expressions in PHP, check out
these sites:
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

A regex to match what you are looking for would be /\{(.+?)\}/, and then
just replace it without the { and } for the replace part.


On Tue, 2004-09-28 at 22:46, Ed Lazor wrote:
 complain
 Today I discovered that my ISP can't upgrade to PHP 5.  They use Plesk for
 server Administration and PHP 5 apparently breaks Plesk.  Plesk says they'll
 make PHP 5 support available as soon as it starts coming default on RedHat
 Enterprise.
 /complain
 
 Unfortunately, I now have a bunch of scripts that require PHP 5.  I'd
 upgraded my beta server for testing and everything has been going so great
 that I went gungho.  Honestly, I tried to not too many of the new features,
 just so I could ease into it and do more testing.  I'm finding little
 differences that I didn't even realize I was taking advantage of.  For
 example, there are a lot of places in the code where I've done something
 like this:
 
 print Learn more about {$product-get_Title()}.br;
 
 I uploaded scripts like this to the production server for more testing and
 PHP4 flagged all of the code like this as parse errors.  I'm not sure, but
 now I'm stuck having to go through all of the code to change the coding
 style  my editor (Dreamweaver MX 2004) allows me to do a global search
 and replace using regular expressions.  I have no idea what regular
 expression I'd use for something like this.  Any recommendations?
 
 Thanks,
 
 Ed
  

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



Re: [PHP] Regular Expression: Markup Code

2004-09-13 Thread Tom Rogers
Hi,

Tuesday, September 14, 2004, 6:04:44 AM, you wrote:
r Hello, would someone please help me with my regular expressions?  They are so
r complex!

 

r Here is what I need to do.  I have a string with contents similar to the
r following:

 

r BLOCK NAME=TOP

 

r(a bunch of markup code)

 

r /BLOCK

r In other words, the name of the block is not known at runtime.  They could be
r anything really!

 

r I need a way to parse through this string, and make new strings with names
r like $TOP, $BOTTOM, $WAYOVERHERE, that contain their markup code, but not the
r BLOCK tags.

 

r Any help would be greatly appreciated!

 

r -Samuel

This should get you started:
?
function callback($a){
print_r($a);
}
$str = END
BLOCK NAME=TOP
   (a bunch of markup code)
/BLOCK

BLOCK NAME=BOTTOM
(a bunch of markup code)
/BLOCK

BLOCK NAME=WAYOVERHERE

(a bunch of markup code)

/BLOCK
END;
preg_replace_callback('!BLOCK NAME=(.*?)(.*?)/BLOCK!is','callback',$str);


Use the call back function to build whatever you need.
-- 
regards,
Tom

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



Re: [PHP] Regular expression help

2004-09-09 Thread John Holmes
From: Skippy [EMAIL PROTECTED]
I'm trying to replace all occurances of the X character in a text
with Y, but only those X's that occur between bold tags (b/b).
?php
$str = 'This X and this X will not be fixed, but bthis X
and/b and hopefully this bX/b should be, along b with
this X also. /b, but not this X.';
function myreplace($match)
{
   $from = 'X';
   $to = 'Y';
   return str_replace($from,$to,$match[0]);
}
$new_str = preg_replace_callback('#b.*/b#Uis','myreplace',$str);
echo $new_str;
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular expression help

2004-09-09 Thread Skippy
Quoting John Holmes [EMAIL PROTECTED]:

 From: Skippy [EMAIL PROTECTED]
  I'm trying to replace all occurances of the X character in a text
  with Y, but only those X's that occur between bold tags (b/b).
 
 ?php
 
 $str = 'This X and this X will not be fixed, but bthis X
 and/b and hopefully this bX/b should be, along b with
 this X also. /b, but not this X.';
 
 function myreplace($match)
 {
 $from = 'X';
 $to = 'Y';
 return str_replace($from,$to,$match[0]);
 }
 
 $new_str = preg_replace_callback('#b.*/b#Uis','myreplace',$str);
 
 echo $new_str;
 
 ?

It works great, thank you. I had tried something on my own previously,
but without the ungreedy modifier and with replacements inside a
repeated while{} cycle instead of a callback. The main drawback in my
version was that an X near hopefully would have been replaced as
well (since technically it is between b and /b). But that wasn't
what I wanted, of course.

-- 
Romanian Web Developers - http://ROWD.ORG

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



Re: [PHP] Regular expression help

2004-08-25 Thread John Holmes
Daniel Lahey wrote:
I'm trying to figure out how to formulate a regular expression that will 
get me everything following a pound sign (#) up to the first space or { 
character.  (I'm trying to parse the ids out of a style sheet.)  Can 
anyone point me in the right direction?  I've been searching on the web 
for hours and reading everything I can find on regular expressions, but 
I just can't wrap my brain around it.  Thanks.
preg_match_all('/#([^\s{]+)/',$style_sheet,$matches);
$matches[1] should have all of the matches...
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular expression help

2004-08-25 Thread Ramil Sagum
On Tue, 24 Aug 2004 23:53:53 -0700, Daniel Lahey [EMAIL PROTECTED] wrote:
 I'm trying to figure out how to formulate a regular expression that
 will get me everything following a pound sign (#) up to the first space
 or { character.  (I'm trying to parse the ids out of a style sheet.)
 Can anyone point me in the right direction?  I've been searching on the
 web for hours and reading everything I can find on regular expressions,
 but I just can't wrap my brain around it.  Thanks.
 


Try this snippet


pre
?php
$css = fopen(http://www.csszengarden.com//001/001.css;, r);
$data = fread($css, 3);
preg_match_all(/#.+({ )/, $data, $out);
print_r($out);
?
/pre

It gets the default css from the zengarden site. (30k is a large
buffer, but this is not a howto on buffered reads)

The regular expression 

/#.+({ )/

means, piece by piece


#  the # character
.  dot is a special character in regular expressions. it can match
any character
+  is also a special character,  it means match 1 or more times

so .+ means match any character 1 or more times

( ) are special characters, they match any single character inside them.

in the case of ({ )  , it matches either a space or a left bracket

So, the whole expression means:

match a strings where they start with #, followed by 1 or more
characters, followed by a space or a left-bracket

Note that these are very simplified explanations for regular expressions. 

Now, try the expression

/#(.+)({ )/

and instead of  print_r($out), try

print_r($out[1]);


Now you get the classnames :)  Check out the following sites for more
info (they appear first when you google regular expressions).

http://sitescooper.org/tao_regexps.html
http://etext.lib.virginia.edu/helpsheets/regex.html


Also, check out the PHP manual for the preg_* functions

---
Note that the script i gave you has problems with classnames on one line, like

#footer a:link, #footer a:visited 

But I won't spoon feed you :)



ramil

http://ramil.sagum.net

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



Re: [PHP] regular expression

2004-07-02 Thread Josh Close
First of all, you might want to put more than one % probably like %%%

Reason is, asp users % % like php uses ? ?.

Just a precaution.

You almost had the regex right.

/%[a-z]+%/i

Thans means, starts with a %, can match a-z, at least once (the +
part) but as many times (greedy), then another %, and the i means
case-insensitive. If you don't have that you'd have to do [a-zA-Z]
instead. Also, will there be anything else in there besides just alpha
chars?

-Josh

On Fri, 2 Jul 2004 13:56:29 -0500, George Lantz
[EMAIL PROTECTED] wrote:
 
 Could someone help me with a regular expression? I am not very good at
 them. I want to find the following pattern inside a file:
 
  [%string%]
 
 Then extract the string portion to store in array.  I would next like to
 replace those patterns with html code. That's right you guessed it a
 template engine type program.
 
 I thought it was/\[\%[a-z]\%\] but I guess I am wrong. Then what
 function do I use to extract.
 
 Thank you,
 George


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



Re: [PHP] Regular Expression Help

2004-06-30 Thread Curt Zirzow
* Thus wrote Pablo Gosse:
 
 Here's the working regular expresssion:
 
 /^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\]{1,999}$/

for starters, that doesn't give me a warning at all.

also, all those escapes arn't needed:

  $reg = '/^[a-zA-Z0-9()]{1}[ a-zA-Z0-9()_,.\'-]{1,999}$/';

The ' is only escaped for php, not the expression. And moving the -
to the end or beginning, you don't need to escape it.

Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

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



Re: Re: [PHP] Regular Expression - it works but uses way too much memory ?

2004-06-19 Thread Ulrik S. Kofod

Robin Vickery sagde:

 The S modifier that you're using means that it's storing the studied
 expression. If the regexp changes each time around the loop then over
 3 iterations, that'll add up. See if removing that modifier helps
 at all.

The S modifier wasn't needed, I added it because I thought it would speed it up but
it didn't. Removing it didn't help on the memory usage, but it performs a little
better without.

 If that's not it, then these *might* save you some memory, although
 I've not tested them:

 I'm not entirely sure why you're matching (.*) at the end then putting
 it back in with your replacement text. Without running it, I'd have
 thought that you could leave out the (.*) from your pattern and the $4
 from your replacement and get exactly the same effect.


I tried removing $4 and (.*) but the result isn't the same, actually my first reg.
exp. didn't have $4, but I had to add it. Without it 51 of the 1246 texts isn't
processed right? Also there isn't really any difference in how it performs with or
without it.


 You could use a non-capturing subpattern for $2 which you're not using
 in your replacement.

   $replace = /^((?:[a-z]+?[^a-z]+?){.($count).})(.$typedmask.)/i;

I didn't know you could do that.. cool :), this made the script run a little faster
but it still uses the same amount of memory.


 And maybe a look-behind assertion for the first subpattern rather than
 a capturing pattern then re-inserting $1.

   $replace = /^(?=(?:[a-z]+?[^a-z]+?){.($count).})(.$typedmask.)/i;
   $with = error-start sourcetext=.$corr['sourcetext']. id=.$corr['id'].
   ...


With ?= I get a lot of warnings:

here is an example:
$replace is '/^(?=(?:[a-z]+?[^a-z]+?){50})(go)(.*)/i'
$with is 'error-start sourcetext=3 id=49 group=- class=- corrected-from=go
corrected-to=god$2error-end sourcetext=3 id=49$3'
br /
bWarning/b:  Compilation failed: lookbehind assertion is not fixed length at
offset 34


with the corrections added the reg.exp. looks like this:
$typedmask = preg_replace(/\s+/,.*?,$corr['typed']);

$replace = '/^((?:[a-z]+?[^a-z]+?){'.($count).'})('.$typedmask.')(.*)/i';

$with = '$1error-start sourcetext='.$corr['sourcetext'].' id='.$corr['id'].'
group='.$corr['grupper'].' class='.$corr['ordklasse'].'
corrected-from='.$corr['typed'].'
corrected-to='.$corr['corrected'].'$2error-end
sourcetext='.$corr['sourcetext'].' id='.$corr['id'].'$3';

$text = $skipText[0] . preg_replace ($replace,$with,$text,1);

It completes a little faster and the output is exactly the same as before,
but it still uses way too much memory.

[EMAIL PROTECTED] testextract]# time php ../export.php  export6.txt
real1m15.851s
user0m18.720s
sys 0m1.750s

From top just before the script completed:
  PID USER PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 7843 root  17   0  269M 269M  3328 R41.7 53.6   0:19 php

This isn't a huge problem anymore, as we have been allowed to move the project to a
3 times faster server with less activity (because of this).

But I would still like to know if there is a solution to this because it seems quite
insane that it allocates more than 250MB memory generate 4MB output.

Thanks Robin! I really appreciate your answer.

Brgds Ulrik

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



Re: [PHP] Regular Expression - it works but uses way too much memory ?

2004-06-18 Thread Ulrik S. Kofod
Sorry to post this again but it's a little urgent.

The preg_replace in my script allocates a little memory every time it is called and
doesn't free it again untill the script ends.

I don't know if it is normal behaviour for preg_replace or if it is my reg. exp.
that causes this.

The problem is that I call preg_replace a little more than 3 times and that
causes quite a lot of memory to be allocated.

Doesn't anybody know if this is a problem in preg_replace or is there a better
maillist/forum for this kind of questions?

Any answer will be appreciated :)


Ulrik S. Kofod sagde:

 $replace = /^(([a-z]+?[^a-z]+?){.($count).})(.$typedmask.)(.*)/iS;
 $with = $1error-start sourcetext=.$corr['sourcetext']. id=.$corr['id'].
 group=\.$corr['grupper'].\ class=\.$corr['ordklasse'].\
 corrected-from=\.$corr['typed'].\
 corrected-to=\.$corr['corrected'].\$3error-end
 sourcetext=.$corr['sourcetext']. id=.$corr['id'].$4;
 $text = preg_replace ($replace,$with,$text,1);


 Above preg_replace works as expected, I have it inside a loop that processes 1000
 texts and replaces a total of 3 words.

 The problem is that it accumulates memory up to 200MB, that isn't freed again until
 the script completes?

 It runs for about 1 - 2 minutes and allocates more and more memory.

 If I comment out the preg_replace the memory usage looks normal, so I'm pretty sure
 that is where the problem is?

 My question is basically, is it something in my reg. exp. that it totally nuts or is
 it normal behaviour for preg_replace to allocate memory and not free it again until
 the script ends?

 --
 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: Re: [PHP] Regular Expression - it works but uses way too much memory ?

2004-06-18 Thread Robin Vickery
On Fri, 18 Jun 2004 08:57:19 +0200 (CEST), Ulrik S. Kofod
[EMAIL PROTECTED] wrote:
 
 Sorry to post this again but it's a little urgent.
 
 The preg_replace in my script allocates a little memory every time it is called and
 doesn't free it again untill the script ends.
 
 I don't know if it is normal behaviour for preg_replace or if it is my reg. exp.
 that causes this.
 
 The problem is that I call preg_replace a little more than 3 times and that
 causes quite a lot of memory to be allocated.
 
  $replace = /^(([a-z]+?[^a-z]+?){.($count).})(.$typedmask.)(.*)/iS;
  $with = $1error-start sourcetext=.$corr['sourcetext']. id=.$corr['id'].
  group=\.$corr['grupper'].\ class=\.$corr['ordklasse'].\
  corrected-from=\.$corr['typed'].\
  corrected-to=\.$corr['corrected'].\$3error-end
  sourcetext=.$corr['sourcetext']. id=.$corr['id'].$4;
  $text = preg_replace ($replace,$with,$text,1);
 
  The problem is that it accumulates memory up to 200MB, that isn't freed again until
  the script completes?

The S modifier that you're using means that it's storing the studied
expression. If the regexp changes each time around the loop then over
3 iterations, that'll add up. See if removing that modifier helps
at all.

  $replace = /^(([a-z]+?[^a-z]+?){.($count).})(.$typedmask.)(.*)/i;

If that's not it, then these *might* save you some memory, although
I've not tested them:

I'm not entirely sure why you're matching (.*) at the end then putting
it back in with your replacement text. Without running it, I'd have
thought that you could leave out the (.*) from your pattern and the $4
from your replacement and get exactly the same effect.

  $replace = /^(([a-z]+?[^a-z]+?){.($count).})(.$typedmask.)/i;
  ...
  sourcetext=.$corr['sourcetext']. id=.$corr['id'].;

You could use a non-capturing subpattern for $2 which you're not using
in your replacement.

  $replace = /^((?:[a-z]+?[^a-z]+?){.($count).})(.$typedmask.)/i;

And maybe a look-behind assertion for the first subpattern rather than
a capturing pattern then re-inserting $1.

  $replace = /^(?=(?:[a-z]+?[^a-z]+?){.($count).})(.$typedmask.)/i;
  $with = error-start sourcetext=.$corr['sourcetext']. id=.$corr['id'].
  ...

   -robin

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



Re: [PHP] Regular expression question

2004-05-27 Thread Rob Ellis
On Thu, May 27, 2004 at 09:59:05AM -0700, Dan Phiffer wrote:
 So I'm trying to implement a simple wiki-like syntax for hyperlinking. 
 Basically I want to match stuff like [this], where the word 'this' gets 
 turned into a hyperlink. I have that working, but I want to be able to 
 escape the opening bracket, so that it's possible to do \[that] without 
 having it match as a link. Here's what I've got:
 
 // Matches fine, but without escaping
 $pattern = 
 /
 \[  # Open bracket
 ([^\]]+?)   # Text, including whitespace
 \]  # Close bracket
 /x
 ;
 
 // Throws an unmatched bracket warning
 $pattern = 
 /
 [^\\]   # Don't match if a backslash precedes
 \[  # Open bracket
 ([^\]]+?)   # Text, including whitespace
 \]  # Close bracket
 /x
 ;
 
 // Ignores escaping: \[example] still matches
 $pattern = 
 /
 [^\\\]  # Don't match if a backslash precedes
 \[  # Open bracket
 ([^\]]+?)   # Text, including whitespace
 \]  # Close bracket
 /x
 ;
 
 Nothing seems to change if I keep adding backslashes to that first 
 matching thingy (i.e. the escaping still doesn't work). Any ideas?
 

Try negative lookbehinds...

  $pattern = '
 /
(?!) \[# open [ not preceded by a backslash
(.*?)   # ungreedy match anything
(?!) \]# close ] not preceded by a backslash
 /x
  ';

- Rob

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



Re: [PHP] Regular expression question

2004-05-27 Thread Justin Patrin
Rob Ellis wrote:
On Thu, May 27, 2004 at 09:59:05AM -0700, Dan Phiffer wrote:
So I'm trying to implement a simple wiki-like syntax for hyperlinking. 
Basically I want to match stuff like [this], where the word 'this' gets 
turned into a hyperlink. I have that working, but I want to be able to 
escape the opening bracket, so that it's possible to do \[that] without 
having it match as a link. Here's what I've got:

// Matches fine, but without escaping
$pattern = 
   /
   \[  # Open bracket
   ([^\]]+?)   # Text, including whitespace
   \]  # Close bracket
   /x
;
// Throws an unmatched bracket warning
$pattern = 
   /
   [^\\]   # Don't match if a backslash precedes
   \[  # Open bracket
   ([^\]]+?)   # Text, including whitespace
   \]  # Close bracket
   /x
;
// Ignores escaping: \[example] still matches
$pattern = 
   /
   [^\\\]  # Don't match if a backslash precedes
   \[  # Open bracket
   ([^\]]+?)   # Text, including whitespace
   \]  # Close bracket
   /x
;
Nothing seems to change if I keep adding backslashes to that first 
matching thingy (i.e. the escaping still doesn't work). Any ideas?


Try negative lookbehinds...
  $pattern = '
 /
(?!) \[# open [ not preceded by a backslash
(.*?)   # ungreedy match anything
(?!) \]# close ] not preceded by a backslash
 /x
  ';
- Rob
BTW, instead of un-greedy maych anything (.*?) You could use a negative 
groupof course to deal with \] as well you have to do alittle more:

([^\]]|[\]])*
--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Regular Expression

2004-05-18 Thread Chris W. Parker
Chris Boget mailto:[EMAIL PROTECTED]
on Tuesday, May 18, 2004 9:55 AM said:

 Why isn't my regex working?  From everything that I've
 read, it should be...

 $string = [joebob];
 
 if( preg_match( '/\[(\s+)\]/i', $string, $aMatches )) {

\s Matches any whitespace character; this is equivalent to the class [
\t\n\r\f\v]. [1]


hth,
chris.

[1] http://www.amk.ca/python/howto/regex/

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



Re: [PHP] Regular Expression

2004-05-18 Thread Ryan Carmelo Briones
Chris Boget wrote:
Why isn't my regex working?  From everything that I've
read, it should be...
script language=php
$string = [joebob];
if( preg_match( '/\[(\s+)\]/i', $string, $aMatches )) {
 print_r( $aMatches );
} else {
 echo 'No match was found' . \n\n;
}
/script
Chris
 

your regex is matching one or more whitespace characters between [ and 
]. i think you wanted \S and not \s. see:  
http://www.php.net/manual/en/pcre.pattern.syntax.php

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


RE: [PHP] Regular Expression

2004-05-05 Thread Martin, Stanley G [Contractor for Sprint]
Here's a neat little tool I came across while taking an ASP.NET course
at a local college for creating regular expressions. I've used it with
my Perl/PHP scripting also. 

Regular Expression Designer
http://www.radsoftware.com.au/web/Default.aspx


Stanley G. Martin
System Administrator
Sprint - EAS Business Intelligence 
[EMAIL PROTECTED]


-Original Message-
From: Tumurbaatar S. [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 05, 2004 12:26 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Regular Expression

There's an input string like {str1,str2,...,strN}. I want to capture
all these strings and due to complexity of them I use a preg_match_all()
instead of simple split. A pattern for the matching strings is ready but
I cannot imagine how to specify that strings are separated by commas
and the last one is not followed by comma. For example, I'm afraid that
this pattern /^{(?:(pattern),)*|(pattern)?}$/ can match and capture
properly constructed input string, but, in addition, this matches if
the string end is ,}. Any ideas?

-- 
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 Expression for a UK mobile phone number

2004-04-08 Thread Michal Migurski
I am trying to create a regular expression for a mobile phone number. The
number must be 12 digits long(0-9) and begin with 447 and have no spaces.
So far I have come up with this but it keeps telling me the number is
invalid even when its correct!

Try this:

$regexp = /447[0-9]{9}/;
  if($_POST[mobile_number] != ''){
if(!preg_match( $regexp, $_POST[mobile_number] )){
  $error = Invalid Mobile Number;
  
header(Location:edit_rep.php?error=$errorrep_id=.$_GET[rep_id].client_id=.$_GET[client_id].rep_name=.$_GET[rep_name].client_name=.$_GET[client_name].);
 exit;
  }
}

Also, your regexp is a little permissive; you can anchor it like so:

$regexp = /^447[0-9]{9}$/;

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] Regular Expression for a UK mobile phone number

2004-04-08 Thread Shaun

Michal Migurski [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I am trying to create a regular expression for a mobile phone number. The
 number must be 12 digits long(0-9) and begin with 447 and have no spaces.
 So far I have come up with this but it keeps telling me the number is
 invalid even when its correct!

 Try this:

 $regexp = /447[0-9]{9}/;
   if($_POST[mobile_number] != ''){
 if(!preg_match( $regexp, $_POST[mobile_number] )){
   $error = Invalid Mobile Number;

header(Location:edit_rep.php?error=$errorrep_id=.$_GET[rep_id].client_i
d=.$_GET[client_id].rep_name=.$_GET[rep_name].client_name=.$_GET[clie
nt_name].);
  exit;
   }
 }

 Also, your regexp is a little permissive; you can anchor it like so:

 $regexp = /^447[0-9]{9}$/;

 -
 michal migurski- contact info and pgp key:
 sf/cahttp://mike.teczno.com/contact.html

Thanks for your reply Michal,

but the regular expression still seems to reject the number...

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



Re: [PHP] Regular Expression for a UK mobile phone number

2004-04-08 Thread Jochem Maas
you should also be considering spaces, leading zeros, brackets, dashes  
international notation.

/^(((\+|00)[- ]?[0-9]{2,3}[- ]?(\(0\))?[- 
]?[1-9]{1}[0-9]{1,})|(0[1-9]{1}[0-9]{1,}))[- ]?(([0-9]{7,})|([0-9]{3}[ 
-]{1}[0-9]{4}))$/

line-wrapping is unintentional, no garantees as to how good it is.

Shaun wrote:

Michal Migurski [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
I am trying to create a regular expression for a mobile phone number. The
number must be 12 digits long(0-9) and begin with 447 and have no spaces.
So far I have come up with this but it keeps telling me the number is
invalid even when its correct!
Try this:

$regexp = /447[0-9]{9}/;
 if($_POST[mobile_number] != ''){
   if(!preg_match( $regexp, $_POST[mobile_number] )){
 $error = Invalid Mobile Number;
header(Location:edit_rep.php?error=$errorrep_id=.$_GET[rep_id].client_i
d=.$_GET[client_id].rep_name=.$_GET[rep_name].client_name=.$_GET[clie
nt_name].);
exit;
 }
}
Also, your regexp is a little permissive; you can anchor it like so:

$regexp = /^447[0-9]{9}$/;

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html


Thanks for your reply Michal,

but the regular expression still seems to reject the number...

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


Re: [PHP] Regular Expression for a UK mobile phone number

2004-04-08 Thread Shaun
Thanks for your reply,

but the number cannot be out side the UK or contain spaces, leading zeros,
brackets or dashes


Jochem Maas [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 you should also be considering spaces, leading zeros, brackets, dashes 
 international notation.

 /^(((\+|00)[- ]?[0-9]{2,3}[- ]?(\(0\))?[-
 ]?[1-9]{1}[0-9]{1,})|(0[1-9]{1}[0-9]{1,}))[- ]?(([0-9]{7,})|([0-9]{3}[
 -]{1}[0-9]{4}))$/

 line-wrapping is unintentional, no garantees as to how good it is.

 Shaun wrote:

  Michal Migurski [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 I am trying to create a regular expression for a mobile phone number.
The
 number must be 12 digits long(0-9) and begin with 447 and have no
spaces.
 So far I have come up with this but it keeps telling me the number is
 invalid even when its correct!
 
 Try this:
 
 $regexp = /447[0-9]{9}/;
   if($_POST[mobile_number] != ''){
 if(!preg_match( $regexp, $_POST[mobile_number] )){
   $error = Invalid Mobile Number;
 
 
 
header(Location:edit_rep.php?error=$errorrep_id=.$_GET[rep_id].client_i
 
d=.$_GET[client_id].rep_name=.$_GET[rep_name].client_name=.$_GET[clie
  nt_name].);
 
  exit;
   }
 }
 
 Also, your regexp is a little permissive; you can anchor it like so:
 
 $regexp = /^447[0-9]{9}$/;
 
 -
 michal migurski- contact info and pgp key:
 sf/cahttp://mike.teczno.com/contact.html
 
 
  Thanks for your reply Michal,
 
  but the regular expression still seems to reject the number...
 

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



Re: [PHP] Regular Expression for a UK mobile phone number

2004-04-08 Thread Michal Migurski
but the regular expression still seems to reject the number...

Can you provide an example of numbers it rejects?

My answer was based on the simple fact that you were testing for numbers
that matched, and returning a rejection based on that. The regexp is
simple enough -- some examples of input where it fails would be good,
perhaps in a reduced case, like:

foreach($array_of_inputs_to_check as $input)
printf(input: %s, matches?: %d\n, $input, check($input);


-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] Regular Expression Help

2004-04-08 Thread Michal Migurski
I want to extract from a large number of html files everything between
the following specified comments, including the comments themselves:

!--Begin CMS Content--...!-- End CMS Content--
snip
And the regular expression I've got is

'/[!--Begin CMS Content\-\-].+[!-- End CMS Content\-\-]/s'

I expected that when I ran this using preg_match_all I would get two
matches

Those brackets mean match one any of the characteres found within, so it
will match '', or '!', or '-', or 'B', or...

You want this:
'/!--Begin CMS Content--(.+)!-- End CMS Content--/Uis'

...which gets you this (I added the parentheses in the middle so you could
also get the stuff inside the CMS content delimiters):

Array
(
[0] = Array
(
[0] = !--Begin CMS Content--
span class=headlineBreadth Requirement/span
hr class=under /
!-- End CMS Content--
[1] = !--Begin CMS Content--
strongMore Matched Content!/strong
!-- End CMS Content--
)

[1] = Array
(
[0] =
span class=headlineBreadth Requirement/span
hr class=under /

[1] =
strongMore Matched Content!/strong

)

)


-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] Regular Expression for a UK mobile phone number

2004-04-08 Thread gohaku
On Apr 8, 2004, at 2:40 PM, Shaun wrote:

Thanks for your reply Michal,

but the regular expression still seems to reject the number...
Just out of curiosity,
Have you tried  if(stripslashes(htmlentities($_POST[mobile_number]) ) 
!= ) ?

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


RE: [PHP] regular expression

2004-04-07 Thread Simon Hayward
preg_match(/To: ([^]+)?([^]+)??/i,$string,$matches);

returns email in $matches[1] in the first instance 
and name in $matches[1] and email in $matches[2] in the second.

-Original Message-
From: Robert Kornfeld [mailto:[EMAIL PROTECTED]
Sent: 07 April 2004 09:32
To: [EMAIL PROTECTED]
Subject: [PHP] regular expression


hey, professionals out there:

i need to write a parser for an email-header to retrieve the email of the
'To:'-field.
there are 2 possibilities:
'To: [EMAIL PROTECTED]' or
'To: first foo [EMAIL PROTECTED]'

i would only need the email-adress!
does anyone know the regular expression that can handle both possibilities?
(i give up!)

thanx!

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


Legal Disclaimer:- 

Internet communications are not secure and therefore the  
Barclays Group does not accept legal responsibility for the 
contents of this message.  Although the Barclays Group 
operates anti-virus programmes, it does not accept 
responsibility for any damage whatsoever that is caused  
by viruses being passed.  Any views or opinions presented  
are solely those of the author and do not necessarily 
represent those of the Barclays Group. 

Replies to this e-mail may be monitored by the Barclays 
Group for operational or business reasons. 

Barclays Bank PLC trading as Shopsmart from Barclaycard. 
Registered Office: 54 Lombard Street 
London EC3P 3AH 
Registered in England, Registration No. 1026167. 

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



Re: [PHP] regular expression

2004-04-07 Thread Red Wingate
Alright,

first of all, in E-Mail Headers every param needs to be written in a 
seperate line, therefore following will work even with multiple recipients:

$recipients = array();
$header = explode( \n , $header );
foreach ( $header AS $param ) {
$param = trim ( $param );

if ( strtolower( substr( $param , 0 , 3 ) ) == 'to:' ) {
$recipients[] = trim ( substr( $param , 3 ) );
}
}

This will match every of these:

'TO:[EMAIL PROTECTED]'
'  TO: [EMAIL PROTECTED]'
' TO:Mr Baz [EMAIL PROTECTED]'
' TO:[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]'

etc. pp

  -- red

PS: I'm not sure about wether 'TO :' is allowed or not - sad thing :-)

Am Mittwoch, 7. April 2004 11:28 schrieb Simon Hayward:
 preg_match(/To: ([^]+)?([^]+)??/i,$string,$matches);

 returns email in $matches[1] in the first instance
 and name in $matches[1] and email in $matches[2] in the second.

 -Original Message-
 From: Robert Kornfeld [mailto:[EMAIL PROTECTED]
 Sent: 07 April 2004 09:32
 To: [EMAIL PROTECTED]
 Subject: [PHP] regular expression


 hey, professionals out there:

 i need to write a parser for an email-header to retrieve the email of the
 'To:'-field.
 there are 2 possibilities:
 'To: [EMAIL PROTECTED]' or
 'To: first foo [EMAIL PROTECTED]'

 i would only need the email-adress!
 does anyone know the regular expression that can handle both possibilities?
 (i give up!)

 thanx!

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


 Legal Disclaimer:-

 Internet communications are not secure and therefore the
 Barclays Group does not accept legal responsibility for the
 contents of this message.  Although the Barclays Group
 operates anti-virus programmes, it does not accept
 responsibility for any damage whatsoever that is caused
 by viruses being passed.  Any views or opinions presented
 are solely those of the author and do not necessarily
 represent those of the Barclays Group.

 Replies to this e-mail may be monitored by the Barclays
 Group for operational or business reasons.

 Barclays Bank PLC trading as Shopsmart from Barclaycard.
 Registered Office: 54 Lombard Street
 London EC3P 3AH
 Registered in England, Registration No. 1026167.

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



Re: [PHP] regular expression

2004-04-07 Thread Curt Zirzow
* Thus wrote Robert Kornfeld ([EMAIL PROTECTED]):
 hey, professionals out there:
 
 i need to write a parser for an email-header to retrieve the email of the
 'To:'-field.
 there are 2 possibilities:
 'To: [EMAIL PROTECTED]' or
 'To: first foo [EMAIL PROTECTED]'

Actually the second one needs to be
  first foo [EMAIL PROTECTED] - or -
  foo [EMAIL PROTECTED]

so you need something like:
  /([^]*([^]+)|(.*))/

That will parse one address. if you have more than one address
you'll have to break the address list apart sperated by ';'

  ie. To: [EMAIL PROTECTED]; foo bar [EMAIL PROTECTED]

  $emails = explode(';', $email_list);

and to get that email address list you'll have to take into account
folding  ie.

To: address;
 address2@
  domain.com


So to allow for this while reading the header lines:

  $last_field = '';
  foreach($headerline) {

// detect a folded header line
if ($headerline{1} == ' ' || $headerline{1} == \t ) {
  $headers[$last_field] .= trim($headerline);
  continue;
}
// check for end of headers
if ($headerline{1} == \n) {
  break;// we're done with headers.
}

//now split the field
list($field, $data) = explode(':', $headerline, 2);

// ensure name is consistent ok
$field = strtolower($field); 

// save the data
$headers[$field] = $data;

// incase its folded
$last_field = $field;
  }

Now apply the other two methods to $headers['to'];


that was a little more than a regex, but I hope it helps.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



[PHP] Re: PHP regular expression

2004-03-11 Thread Justin Patrin
Mike Mapsnac wrote:

Hello

I found this function online and want to understand how it works.
I don't understand /^ and $/. I know that ^ beginning of the 
string but what is /^.

Thanks

function validEmail($email)
{
   return 
preg_match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+[a-zA-Z0-9_-]$/,$email); 

}

_
Fast. Reliable. Get MSN 9 Dial-up - 3 months for the price of 1! 
(Limited-time Offer) 
http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/
The / characters are the regex delimiters. This is a throwback to the 
Perl language. Basically, the / show where the beginning and end of the 
regex is. You *MUST* have them. After the last / you can put modifiers 
such as 'i' for case insensitive matching.

You can also use other chars for delimiters, but I try to stick with / 
for consistency.

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


Re: [PHP] Re: PHP regular expression

2004-03-11 Thread Jason Davidson
I think he meant.. the carrot after the delimiter
which means NOT.. like /[^a]/   means match anything thats not an 'a'

Jason

Justin Patrin [EMAIL PROTECTED] wrote:
 
 Mike Mapsnac wrote:
 
  Hello
  
  I found this function online and want to understand how it works.
  I don't understand /^ and $/. I know that ^ beginning of the 
  string but what is /^.
  
  Thanks
  
  function validEmail($email)
  {
 return 
 
 preg_match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+[a-zA-Z0-9_-]$/,$email);
 
  
  }
  
  _
  Fast. Reliable. Get MSN 9 Dial-up - 3 months for the price of 1! 
  (Limited-time Offer) 
  http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/
 
 The / characters are the regex delimiters. This is a throwback to the 
 Perl language. Basically, the / show where the beginning and end of the 
 regex is. You *MUST* have them. After the last / you can put modifiers 
 such as 'i' for case insensitive matching.
 
 You can also use other chars for delimiters, but I try to stick with / 
 for consistency.
 
 -- 
 paperCrane Justin Patrin
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP] Re: PHP regular expression

2004-03-11 Thread Michal Migurski
 preg_match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+[a-zA-Z0-9_-]$/,$email);

 The / characters are the regex delimiters. This is a throwback to the
 Perl language. Basically, the / show where the beginning and end of the
 regex is. You *MUST* have them. After the last / you can put modifiers
 such as 'i' for case insensitive matching.

 You can also use other chars for delimiters, but I try to stick with /
 for consistency.

I think he meant.. the carrot after the delimiter which means NOT.. like
/[^a]/ means match anything thats not an 'a'

In the case above, the caret means the beginning of a pattern. It only
negates a pattern in the [] context:

/^a/ means an 'a' at the beginning of the pattern
/[^a]/ means a char that is not an 'a'
/^[^a]/ means a char that is not an 'a' at the beginning of a pattern

FYI, the O'reilly Learning Perl book has the best introduction to
perl regexp's I've seen yet; I still use it as an indispensable reference.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] Regular expression help?

2004-02-02 Thread Adam Bregenzer
On Mon, 2004-02-02 at 14:15, Jas wrote:
 I have tried this but its not working.

 !eregi(^[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$,$_POST['mac'])
 
 so it should match 2 characters 0-9a-fA-F
 each block of 2 characters is followed by a : and repreated in 6
 blocks.

That's a long expression, try:
!preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']);

This pattern finds 6 matches of a number or letter (the /i means
case-insensitive) followed by either a ':' or the end of the string.

-- 
Adam Bregenzer
[EMAIL PROTECTED]

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



Re: [PHP] Regular expression help?

2004-02-02 Thread Jas
Adam Bregenzer wrote:

On Mon, 2004-02-02 at 14:15, Jas wrote:

I have tried this but its not working.
			 
!eregi(^[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$,$_POST['mac'])

so it should match 2 characters 0-9a-fA-F
each block of 2 characters is followed by a : and repreated in 6
blocks.


That's a long expression, try:
!preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']);
This pattern finds 6 matches of a number or letter (the /i means
case-insensitive) followed by either a ':' or the end of the string.
Thanks, that worked like a charm.
Jas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular expression help?

2004-02-02 Thread Justin Patrin
Jas wrote:

Adam Bregenzer wrote:

On Mon, 2004-02-02 at 14:15, Jas wrote:

I have tried this but its not working.
 
!eregi(^[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$,$_POST['mac']) 

so it should match 2 characters 0-9a-fA-F
each block of 2 characters is followed by a : and repreated in 6
blocks.


That's a long expression, try:
!preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']);
This pattern finds 6 matches of a number or letter (the /i means
case-insensitive) followed by either a ':' or the end of the string.
Thanks, that worked like a charm.
Jas
You may want to check out The Regex Coach. It's very helpful. :-)
http://www.weitz.de/regex-coach/
--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Brad Pauly
On Fri, 2004-01-16 at 09:49, Tobias Engelhardt wrote:
 Hi list,
 i hope someone can help me out... i have to replace
 
 a href=order.php?order_id=12345
 with
 a href=order_12345.html
 
 any ideas? thank you!

What about just using the variable to build the name?

$file_name = 'order_'.$_GET['order_id'].'.html';

- Brad

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



Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Tobias Engelhardt
That is not possible because the id's are hard-coded in thousands of 
html-pages. Not a very good idea, i know. It wasn't mine... I *have* to 
use search/replace. (A script processes each file in the directory)

Brad Pauly wrote:

What about just using the variable to build the name?

$file_name = 'order_'.$_GET['order_id'].'.html';

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


Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Mike Migurski
i hope someone can help me out... i have to replace

a href=order.php?order_id=12345
with
a href=order_12345.html

any ideas? thank you!

PCRE style:
'/a href=order.php\?order_id=(\d+)/'
replaced by 'a href=order_$1.html'.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Brad Pauly
On Fri, 2004-01-16 at 10:07, Tobias Engelhardt wrote:
 That is not possible because the id's are hard-coded in thousands of 
 html-pages. Not a very good idea, i know. It wasn't mine... I *have* to 
 use search/replace. (A script processes each file in the directory)

Ah, I see. I think you could use str_replace (untested):

$a = 'order.php?order_id=';
$b = 'order_';
$c = 'a href=order.php?order_id=12345';

$new = str_replace($a, $b, $c).'.html';

- Brad

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



Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Brad Pauly
On Fri, 2004-01-16 at 10:21, Brad Pauly wrote:
 On Fri, 2004-01-16 at 10:07, Tobias Engelhardt wrote:
  That is not possible because the id's are hard-coded in thousands of 
  html-pages. Not a very good idea, i know. It wasn't mine... I *have* to 
  use search/replace. (A script processes each file in the directory)
 
 Ah, I see. I think you could use str_replace (untested):
 
 $a = 'order.php?order_id=';
 $b = 'order_';
 $c = 'a href=order.php?order_id=12345';
 
 $new = str_replace($a, $b, $c).'.html';

Whewps. I just realized I didn't pull the '' off the end.

- Brad

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



Re: [PHP] Regular Expression for Search/Replace

2004-01-16 Thread Tobias Engelhardt
Thanks, that solved the problem...



Mike Migurski wrote:

i hope someone can help me out... i have to replace

a href=order.php?order_id=12345
with
a href=order_12345.html
any ideas? thank you!


PCRE style:
'/a href=order.php\?order_id=(\d+)/'
replaced by 'a href=order_$1.html'.
-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

--

Teamnet GmbH

Technologiepark 20
33100 Paderborn
Tel.: 0 52 51 / 68 77 22
Fax: 0 52 51 / 68 77 21
www.teamnet.de
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression

2003-12-29 Thread lingua2001
Thank you!! It worked!!

The wrong sample was 'dot'11'dot'abcd, but
the first dot was not shown properly...

And, now I have another problem:
In fact, the input strings are lines from a webpage, and
they sometimes have line-feed as in:

$string = 
11.abcd.32.efgh.54.ij --here
kh.41.lmno. --here
63.pqrs;

And, with ereg_replace((\.)([0-9]),\\1brbr\\2,$string),
 the result I expect is:

 11.abcd.

32.efgh.

54.ijkh.

41.lmno.

63.pqrs.

But, the actual result is:

11.abcd.

32.efgh.

54.ij -- problem
kh.

41.lmno.
63.pqrs. -- problem

I tried some more regular expressions to solve this, but
they don work yet.
So, please help me~~

Thank you in advance.

Joshua

- Original Message -
Wrom: WIGYOKSTTZRCLBDXRQBGJSNBOHMKHJYFMYXOEAIJJ
To: Joshua [EMAIL PROTECTED]
Cc: PHP General list [EMAIL PROTECTED]
Sent: Saturday, December 27, 2003 1:27 PM
Subject: Re: [PHP] Regular Expression


 On Sat, 27 Dec 2003, Joshua wrote:
  I'm trying to change the string, for example,
 
  $string = 11.abcd.32.efgh.53.ijk;
  to
 
  11.abcd.
  32.efgh.
  53.ijk.
 
  with ereg_replace. Like
  ereg_replace(\.[0-9],BR,$string);
  How can I recover the original characters after replacing them with BR
  in ereg_replace?
 
  ereg_replace(\.[0-9],BR\\0,$string) gives me the
  wrong result like:
 
  11.abcd.
  32.efgh.
  53.ijk.

 Since the output you want and the output you didn't want are identical in
 your post, it was hard to tell what you were trying to do, but...

 I think this is what you want..
 ereg_replace((\.)([0-9]),\\1br\\2,$string);
 (minus the last decimal point, missing from your original string)

 --
 Kelly Hallman
 // Ultrafancy

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



- Original Message -
Wrom: PHSCRTNHGSWZIDREXCAXZOWCONEUQZAAFXISHJEXX
To: Joshua [EMAIL PROTECTED]
Cc: PHP General list [EMAIL PROTECTED]
Sent: Saturday, December 27, 2003 1:27 PM
Subject: Re: [PHP] Regular Expression


 On Sat, 27 Dec 2003, Joshua wrote:
  I'm trying to change the string, for example,
 
  $string = 11.abcd.32.efgh.53.ijk;
  to
 
  11.abcd.
  32.efgh.
  53.ijk.
 
  with ereg_replace. Like
  ereg_replace(\.[0-9],BR,$string);
  How can I recover the original characters after replacing them with BR
  in ereg_replace?
 
  ereg_replace(\.[0-9],BR\\0,$string) gives me the
  wrong result like:
 
  11.abcd.
  32.efgh.
  53.ijk.

 Since the output you want and the output you didn't want are identical in
 your post, it was hard to tell what you were trying to do, but...

 I think this is what you want..
 ereg_replace((\.)([0-9]),\\1br\\2,$string);
 (minus the last decimal point, missing from your original string)

 --
 Kelly Hallman
 // Ultrafancy

 --
 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 Expression

2003-12-27 Thread Kelly Hallman
On Sat, 27 Dec 2003, Joshua wrote:
 I'm trying to change the string, for example,

 $string = 11.abcd.32.efgh.53.ijk;
 to
 
 11.abcd.
 32.efgh.
 53.ijk.
 
 with ereg_replace. Like 
 ereg_replace(\.[0-9],BR,$string);
 How can I recover the original characters after replacing them with BR
 in ereg_replace?
 
 ereg_replace(\.[0-9],BR\\0,$string) gives me the
 wrong result like:
 
 11.abcd.
 32.efgh.
 53.ijk.

Since the output you want and the output you didn't want are identical in
your post, it was hard to tell what you were trying to do, but...

I think this is what you want..
ereg_replace((\.)([0-9]),\\1br\\2,$string);
(minus the last decimal point, missing from your original string)

-- 
Kelly Hallman
// Ultrafancy

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



Re: [PHP] Regular Expression

2003-12-27 Thread Joshua
Thank you!! It worked!!

The wrong sample was 'dot'11'dot'abcd, but
the first dot was not shown properly...

And, now I have another problem:
In fact, the input strings are lines from a webpage, and
they sometimes have line-feed as in:

11.abcd.32.efgh.54.ij --here
kh.41.lmno. --here
63.pqrs

And, with ereg_replace((\.)([0-9]),\\1brbr\\2,$string),
 the result I expect is:

 11.abcd.

32.efgh.

54.ijkh.

41.lmno.

63.pqrs.

But, the actual result is:

11.abcd.

32.efgh.

54.ij -- problem
kh.

41.lmno.
63.pqrs. -- problem

I tried some more regular expressions to solve this, but
they don work yet.
So, please help me~~

Thank you in advance.

Joshua

- Original Message -
From: Kelly Hallman [EMAIL PROTECTED]
To: Joshua [EMAIL PROTECTED]
Cc: PHP General list [EMAIL PROTECTED]
Sent: Saturday, December 27, 2003 1:27 PM
Subject: Re: [PHP] Regular Expression


 On Sat, 27 Dec 2003, Joshua wrote:
  I'm trying to change the string, for example,
 
  $string = 11.abcd.32.efgh.53.ijk;
  to
 
  11.abcd.
  32.efgh.
  53.ijk.
 
  with ereg_replace. Like
  ereg_replace(\.[0-9],BR,$string);
  How can I recover the original characters after replacing them with BR
  in ereg_replace?
 
  ereg_replace(\.[0-9],BR\\0,$string) gives me the
  wrong result like:
 
  11.abcd.
  32.efgh.
  53.ijk.

 Since the output you want and the output you didn't want are identical in
 your post, it was hard to tell what you were trying to do, but...

 I think this is what you want..
 ereg_replace((\.)([0-9]),\\1br\\2,$string);
 (minus the last decimal point, missing from your original string)

 --
 Kelly Hallman
 // Ultrafancy

 --
 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 Expression Help Please

2003-12-01 Thread Rory McKinley
On 27 Nov 2003 at 11:48, Shaun wrote:

 Hi,
 
 I need to generate a lowercase alphanumeric passwrord thats 8 characters
 long, has anyone got a function that can do this?
 
 Thanks for your help
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

Umm, I don't know of a function already definedbut it shouldn't be that hard to 
generate .in pseudocode :

1.Create an array containing the lower case letters as well as the digits
2. Pick a random integer between 0 and 35 (n)
3. Retrieve the character in array[n]
4. Add to password string.
5. Loop through another seven times

HTH

Rory McKinley
Nebula Solutions
+27 82 857 2391
[EMAIL PROTECTED]
There are 10 kinds of people in this world, 
those who understand binary and those who don't (Unknown)

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



Re: [PHP] regular expression, image, name, alt, title, preg_match_all

2003-12-01 Thread Sophie Mattoug
Adam i Agnieszka Gasiorowski FNORD wrote:

I'm trying to develop a regex for matching
with preg_match_all, I want to match such things
like image name, image alt text, image title in
construct like this:
html...
div class=class style=style
 img src=img=name alt=alt title=title /
 span class=class style=style
  text
 /span
/div
html...
The rexex as for now is:
define(
   'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',
   '{
(?:\s*img\s+src\s*=\s*(?:|\')?\s*(?:img)?\s*=\s*)   #  img
(?\b\S+\b)   # name
(?:title\s*=\s*(?:|\'))  # title
(?\b\S*\b)
(?:|\')*\s*  
(?:alt\s*=\s*(?:|\'))# alt
(?\b\S*\b)
(?:|\')*\s*   
(?:\|\'||/|\s) # img /
}Uix'
 );

, but it does not match. How can I fix it?
 

It's not so easy to match an entire IMG tag, because first of all the 
attributes are not always in the same order. If I were you, this is what 
I would do :
ereg(img ([^]+), $your_text, $img_array);
$i = 0;
foreach ($img_array as $img) {
 while (ereg(^(.+)=\(.+)\, , $img, $regs))
   $images[$i][$regs[1]] = $regs[2];
 $i++;
}

Hope this helps,

--
Cordialement,
---
Sophie Mattoug
Dveloppement web dynamique
[EMAIL PROTECTED]
---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regular expression, image, name, alt, title, preg_match_all

2003-12-01 Thread Sophie Mattoug
Sophie Mattoug wrote:

Adam i Agnieszka Gasiorowski FNORD wrote:

I'm trying to develop a regex for matching
with preg_match_all, I want to match such things
like image name, image alt text, image title in
construct like this:
html...
div class=class style=style
 img src=img=name alt=alt title=title /
 span class=class style=style
  text
 /span
/div
html...
The rexex as for now is:
define(
   'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',
   '{
(?:\s*img\s+src\s*=\s*(?:|\')?\s*(?:img)?\s*=\s*)   #  
img
(?\b\S+\b)   # name
(?:title\s*=\s*(?:|\'))  # 
title
(?\b\S*\b)
(?:|\')*\s*  
(?:alt\s*=\s*(?:|\'))# alt
(?\b\S*\b)
(?:|\')*\s*   
(?:\|\'||/|\s) # img /
}Uix'
 );

, but it does not match. How can I fix it?
 

It's not so easy to match an entire IMG tag, because first of all the 
attributes are not always in the same order. If I were you, this is 
what I would do :
ereg(img ([^]+), $your_text, $img_array);
$i = 0;
foreach ($img_array as $img) {
 while (ereg(^(.+)=\(.+)\, , $img, $regs))
   $images[$i][$regs[1]] = $regs[2];
 $i++;
}

Hope this helps,


Sorry I made a mistake. Better do this:
ereg(img ([^]+), $your_text, $img_array);
$i = 0;
foreach ($img_array as $img) {
while (ereg(^(.+)=\(.+)\(.+)$, , $img, $regs))  {
  $images[$i][$regs[1]] = $regs[2];
   $img = $regs[3];
 }
$i++;
}
--
Cordialement,
---
Sophie Mattoug
Dveloppement web dynamique
[EMAIL PROTECTED]
---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] regular expression, image, name, alt, title, preg_match_all

2003-12-01 Thread Wouter van Vliet
Sophie Mattoug wrote:
 Adam i Agnieszka Gasiorowski FNORD wrote:
 
  I'm trying to develop a regex for matching  with preg_match_all, I
 want to match such things  like image name, image alt text, image
 title in  construct like this: 
 
 html...
 div class=class style=style
  img src=img=name alt=alt title=title /  span class=class
   style=style text
  /span
 /div
 html...
 The rexex as for now is:
 
 define(
'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',   
 '{ (?:\s*img\s+src\s*=\s*(?:|\')?\s*(?:img)?\s*=\s*)
   #  img
 (?\b\S+\b)
   # name
 (?:title\s*=\s*(?:|\'))
   # title
 (?\b\S*\b)
 (?:|\')*\s*
 (?:alt\s*=\s*(?:|\'))
   # alt
 (?\b\S*\b)
 (?:|\')*\s*
 (?:\|\'||/|\s)
   # img /
 }Uix'
  );
 

My approach would be somewhat something good from both worlds it IS
possible to match an entire image tag with preg_match_all:

/img (\s*(alt|src|style|title|name)=\s*([^]*)\s*)*\/?/i

Of course, this is not tested .. but should come at least a bit close to
what you want ...

Wouter

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



Re: [PHP] regular expression, image, name, alt, title, preg_match_all

2003-12-01 Thread Adam i Agnieszka Gasiorowski FNORD
Sophie Mattoug wrote:
 
 Adam i Agnieszka Gasiorowski FNORD wrote:
 
I'm trying to develop a regex for matching
  with preg_match_all, I want to match such things
  like image name, image alt text, image title in
  construct like this:
 
  html...
  div class=class style=style
   img src=img=name alt=alt title=title /
   span class=class style=style
text
   /span
  /div
  html...
  The rexex as for now is:
 
 define(
 'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',
 '{
  (?:\s*img\s+src\s*=\s*(?:|\')?\s*(?:img)?\s*=\s*)   #  img
  (?\b\S+\b)   # name
  (?:title\s*=\s*(?:|\'))  # title
  (?\b\S*\b)
  (?:|\')*\s*
  (?:alt\s*=\s*(?:|\'))# alt
  (?\b\S*\b)
  (?:|\')*\s*
  (?:\|\'||/|\s) # img /
  }Uix'
   );
 
  , but it does not match. How can I fix it?
 
 
 
 It's not so easy to match an entire IMG tag, because first of all the
 attributes are not always in the same order. If I were you, this is what
 I would do :
 ereg(img ([^]+), $your_text, $img_array);
 $i = 0;
 foreach ($img_array as $img) {
   while (ereg(^(.+)=\(.+)\, , $img, $regs))
 $images[$i][$regs[1]] = $regs[2];
   $i++;
 }
 
 Hope this helps,

What I 
 really want to get out of this regex is
 1) image name
 2) image alt text
 3) image title text
 , so only those three parentheses are of capturing
 kind and the rest is marked as non-capturing...
 I wonder will this work (if I change this part):
 (?:
  (?:title\s*=\s*(?:|\'))  # title
  (?\b\S*\b)
  (?:|\')*\s*
 |
  (?:alt\s*=\s*(?:|\'))# alt
  (?\b\S*\b)
  (?:|\')*\s*
 )

 , notice the or character. I guess it should
 match, as the order is not important now...
 I love monster regexes ;8].

-- 
Seks, seksi, seksolatki... news:pl.soc.seks.moderowana
http://hyperreal.info  { iWanToDie }   WiNoNa)   (
http://szatanowskie-ladacznice.0-700.pl  foReVeR(  *  )
Poznaj jej zwiewne ksztaty... http://www.opera.com 007

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



Re: [PHP] regular expression, image, name, alt, title, preg_match_all

2003-12-01 Thread Adam i Agnieszka Gasiorowski FNORD
Sophie Mattoug wrote:
 
 Sophie Mattoug wrote:
 
  Adam i Agnieszka Gasiorowski FNORD wrote:
 
  I'm trying to develop a regex for matching
  with preg_match_all, I want to match such things
  like image name, image alt text, image title in
  construct like this:
 
  html...
  div class=class style=style
   img src=img=name alt=alt title=title /
   span class=class style=style
text
   /span
  /div
  html...
  The rexex as for now is:
 
  define(
 'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',
 '{
  (?:\s*img\s+src\s*=\s*(?:|\')?\s*(?:img)?\s*=\s*)   #
  img
  (?\b\S+\b)   # name
  (?:title\s*=\s*(?:|\'))  #
  title
  (?\b\S*\b)
  (?:|\')*\s*
  (?:alt\s*=\s*(?:|\'))# alt
  (?\b\S*\b)
  (?:|\')*\s*
  (?:\|\'||/|\s) # img /
  }Uix'
   );
 
  , but it does not match. How can I fix it?
 
 
 
  It's not so easy to match an entire IMG tag, because first of all the
  attributes are not always in the same order. If I were you, this is
  what I would do :
  ereg(img ([^]+), $your_text, $img_array);
  $i = 0;
  foreach ($img_array as $img) {
   while (ereg(^(.+)=\(.+)\, , $img, $regs))
 $images[$i][$regs[1]] = $regs[2];
   $i++;
  }
 
  Hope this helps,
 
 Sorry I made a mistake. Better do this:
 ereg(img ([^]+), $your_text, $img_array);
 $i = 0;
 foreach ($img_array as $img) {
  while (ereg(^(.+)=\(.+)\(.+)$, , $img, $regs))  {
$images[$i][$regs[1]] = $regs[2];
 $img = $regs[3];
   }
  $i++;
 }

Ah, now I get it. I'll try it 
 (with preg-functions, as I prefer them).

So I'll get something like

 $images = array(
 [0] = array(
  src = 'image1.jpg',
  alt = '',
  title = 'a cow'
 ),
 [1] ...
)

 ...nice :8]. Thank you!

-- 
Seks, seksi, seksolatki... news:pl.soc.seks.moderowana
http://hyperreal.info  { iWanToDie }   WiNoNa)   (
http://szatanowskie-ladacznice.0-700.pl  foReVeR(  *  )
Poznaj jej zwiewne ksztaty... http://www.opera.com 007

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



Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-28 Thread David T-G
Adam --

...and then Adam i Agnieszka Gasiorowski FNORD said...
% 
...
%   How about,
% 
%  $password = strtolower(substr(md5(uniqid(time())), 0, 7));

Hey, that's pretty slick.  Good one!  Gonna have to remember that; it's
an excellent trick.


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Regular expression tutorial

2003-11-27 Thread Jeroen Serpieters
This should do it, also check the links on the left.
http://php.net/manual/nl/pcre.pattern.syntax.php

Citeren [EMAIL PROTECTED] [EMAIL PROTECTED]:

 Hi,
 
 I see from the postings that I should learn Regular Expressions quite fast.
 
 Is there somewhere a decent online tutorial you could recommend?
 
 Thanks
 
 Nico
 
 -- 
 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 Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread David T-G
Shaun --

[No need to post twice...]

...and then Shaun said...
% 
% Hi,

Hi!


% 
% I need to generate a lowercase alphanumeric passwrord thats 8 characters
% long, has anyone got a function that can do this?

This isn't really a regular expression question, since you'd use an
expression to check if a string matched your requirements but not to
generate such a string.

A function should be easy: just loop 8 times over spitting out a random
char between a and z or 0 and 9 (use rand() to generate a number between
0 and 35 and then map that to the char).


% 
% Thanks for your help

Enjoy :-)


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Bogdan Stancescu
...as in...

?
  // Could've been done with ASCII sets, but this way
  // you can easily tweak the eligible characters.
  $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
  $pwdLen=8;
  $password='';
  for($i=0;$i$pwdLen;$i++) {
$password.=$eligible[rand(0,strlen($eligible))];
  }
  echo(Your new password: $password\n);
?
Bogdan

David T-G wrote:
Shaun --

[No need to post twice...]

...and then Shaun said...
% 
% Hi,

Hi!

% 
% I need to generate a lowercase alphanumeric passwrord thats 8 characters
% long, has anyone got a function that can do this?

This isn't really a regular expression question, since you'd use an
expression to check if a string matched your requirements but not to
generate such a string.
A function should be easy: just loop 8 times over spitting out a random
char between a and z or 0 and 9 (use rand() to generate a number between
0 and 35 and then map that to the char).
% 
% Thanks for your help

Enjoy :-)

HTH  HAND

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


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread David T-G
Bogdan --

...and then Bogdan Stancescu said...
% 
% ...as in...
% 
% ?
%   // Could've been done with ASCII sets, but this way
%   // you can easily tweak the eligible characters.
%   $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
%   $pwdLen=8;
%   $password='';
%   for($i=0;$i$pwdLen;$i++) {
% $password.=$eligible[rand(0,strlen($eligible))];
%   }
%   echo(Your new password: $password\n);
% ?

Looks good to me.  You're too kind; I was going to leave the exercise to
the student to complete :-)


% 
% Bogdan


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Burhan Khalid
Shaun wrote:

Hi,

I need to generate a lowercase alphanumeric passwrord thats 8 characters
long, has anyone got a function that can do this?
No, but I can write a quick one for you. Can't guarantee the uniqueness 
of the password being generated.

function passgen()
{
   srand((float) microtime() * 1000);
   //Source arrays
   $letters = range('a','z');
   $digits  = range(1,9);
   //Get random items from arrays
   $char = array_rand($letters, 4);
   $num  = array_rand($digits, 4);
   //Combine the two random items into one array
   for ($i = 0; $i 4; ++$i)
   {
 $ran_char[] = $letters[$char[$i]];
 $ran_num[]  = $digits[$num[$i]];
   }
   //build our password
   $password = array_unique(array_merge($ran_char, $ran_num));
   //randomize it
   shuffle($password);
   return join(,$password);
}
echo passgen();

?

--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com
---
Documentation is like sex: when it is good,
 it is very, very good; and when it is bad,
 it is better than nothing.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Adam i Agnieszka Gasiorowski FNORD
David T-G wrote:
 
 Bogdan --
 
 ...and then Bogdan Stancescu said...
 %
 % ...as in...
 %
 % ?
 %   // Could've been done with ASCII sets, but this way
 %   // you can easily tweak the eligible characters.
 %   $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
 %   $pwdLen=8;
 %   $password='';
 %   for($i=0;$i$pwdLen;$i++) {
 % $password.=$eligible[rand(0,strlen($eligible))];
 %   }
 %   echo(Your new password: $password\n);
 % ?
 
 Looks good to me.  You're too kind; I was going to leave the exercise to
 the student to complete :-)

  How about,

 $password = strtolower(substr(md5(uniqid(time())), 0, 7));

  Will get you a unique password consisting of 8 
 rather random lowercase alphanumerics.

-- 
Seks, seksi, seksolatki... news:pl.soc.seks.moderowana
http://hyperreal.info  { iWanToDie }   WiNoNa)   (
http://szatanowskie-ladacznice.0-700.pl  foReVeR(  *  )
Poznaj jej zwiewne ksztaty... http://www.opera.com 007

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



RE: [PHP] Regular expression help

2003-11-25 Thread Bronislav Kluka
This condition is true if there is no space, new line or tabulator in $val

 I need someone to tell me exactly what this regular-expression means:
 if(ereg([^ \t\n],$val)) {
 // do the job here
 }

 I'm looking for an intermittent bug, and I need to understand this to make
 sure I have found the bug.

 Thanks

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




S pozdravem
Bronislav Klucka

=[ pro2-soft.com ]=
Bronislav Klucka  Pro2-Soft
+420 605 582 922 [EMAIL PROTECTED]

* Windows  Web applications, Computer traininghttp://pro2-soft.com
---

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



Re: [PHP] Regular expression help

2003-11-25 Thread Ben
Thanks Bronislav for your answer but this can't be it as the following test
code passes validation:
?Php
$val = \t  test \n;
if(ereg([^ \t\n],$val)) {
 echo 'In here!!';
}
echo 'BR' . nl2br($val);
?

Anyone has an idea?

Bronislav kluèka [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 This condition is true if there is no space, new line or tabulator in $val
 
  I need someone to tell me exactly what this regular-expression means:
  if(ereg([^ \t\n],$val)) {
  // do the job here
  }
 
  I'm looking for an intermittent bug, and I need to understand this to
make
  sure I have found the bug.
 
  Thanks
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 



 S pozdravem
 Bronislav Klucka

 =[
pro2-soft.com ]=
 Bronislav Klucka
Pro2-Soft
 +420 605 582 922
[EMAIL PROTECTED]

 * Windows  Web applications, Computer training
http://pro2-soft.com
 --
-

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



Re: [PHP] Regular expression help

2003-11-25 Thread Matthias Nothhaft
Hi,

^ inside [] means not the following chars, so your expression means:

if ($val contains no space  , no tab \t and no newline \n) {
//do the job ...
}
Regards,
Matthias


Ben wrote:
I need someone to tell me exactly what this regular-expression means:
if(ereg([^ \t\n],$val)) {
// do the job here
}
I'm looking for an intermittent bug, and I need to understand this to make
sure I have found the bug.
Thanks

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


Re: [PHP] Regular expression help

2003-11-25 Thread CPT John W. Holmes
From: Bronislav Kluka [EMAIL PROTECTED]
  I need someone to tell me exactly what this regular-expression means:
  if(ereg([^ \t\n],$val)) {
  // do the job here

 This condition is true if there is no space, new line or tabulator in $val

Actually, the regular expression will match anything that is NOT a space,
tab, or newline. That's what the ^ character does (negates the matching).
So, if $val has anything that is NOT a space, newline, or tab in it, then
the ereg() function will return true.

---John Holmes...

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



Re: [PHP] Regular expression help

2003-11-25 Thread Ben
That's it!
Thank you very much, you have the answer.

I wonder why the programmer did not write the following line instead:
if (strlen(trim($val))) {
// Do the job here
}

Anyways, you just proved that I did not fix the bug! Now I have to work even
more! :-P
Thanks


Matthias Nothhaft [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 ^ inside [] means not the following chars, so your expression means:

 if ($val contains no space  , no tab \t and no newline \n) {
 //do the job ...
 }

 Regards,
 Matthias



 Ben wrote:
  I need someone to tell me exactly what this regular-expression means:
  if(ereg([^ \t\n],$val)) {
  // do the job here
  }
 
  I'm looking for an intermittent bug, and I need to understand this to
make
  sure I have found the bug.
 
  Thanks
 

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



Re: [PHP] Regular expression help

2003-11-25 Thread Curt Zirzow
* Thus wrote Matthias Nothhaft ([EMAIL PROTECTED]):
 Hi,
 
 ^ inside [] means not the following chars, so your expression means:
 
 if ($val contains no space  , no tab \t and no newline \n) {
   //do the job ...
 }

That's not necessarily the correct assesment. rather:
  if ($val has any character but ' ', '\t', or '\n') {
// do the job.
  }

with:   test\t\n
 because 'test' is in there it results a a true statement.


Curt
-- 
My PHP key is worn out

  PHP List stats since 1997: 
http://zirzow.dyndns.org/html/mlists/

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



Re: [PHP] Regular Expression

2003-08-14 Thread Jason Wong
On Tuesday 05 August 2003 04:19, Ralph Guzman wrote:
 Been working on this one for a while but can't get it working properly.
 I need a regular expression to match if address is

 1. PO Box
 2. P.O. Box
 3. P.O.Box

 I'm using /i to make this case insensitive.

 I got it working with 1  2, but it's still not matching 3. Any
 suggestions?

 if(preg_match( /p[\.]o\.* +box/i, trim($_POST['address'])){
echo Address is P.O. BOX;
 }

Try:

 /p\.?o\.?( )?box/i

-- 
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
--
/*
Age before beauty; and pearls before swine.
-- Dorothy Parker
*/


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



RE: [PHP] Regular Expression

2003-08-04 Thread Jennifer Goodie
 Been working on this one for a while but can't get it working properly.
 I need a regular expression to match if address is

 1. PO Box
 2. P.O. Box
 3. P.O.Box

 I got it working with 1  2, but it's still not matching 3. Any
 suggestions?

 if(preg_match( /p[\.]o\.* +box/i, trim($_POST['address'])){
echo Address is P.O. BOX;
 }

You are using a + as the modifier on the space between p.o. and box.  +
means 1 or more.  Option 3 does not have a space.  Try using * which is 0 or
more, or ? which is 0 or 1.


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



Re: [PHP] Regular Expression

2003-08-04 Thread Jon Drukman
At 02:45 PM 8/4/2003, Ralph Guzman wrote:
Been working on this one for a while but can't get it working properly.
I need a regular expression to match if address is
1. PO Box
2. P.O. Box
3. P.O.Box
I'm using /i to make this case insensitive.

I got it working with 1  2, but it's still not matching 3. Any
suggestions?
if(preg_match( /p[\.]o\.* +box/i, trim($_POST['address'])){
   echo Address is P.O. BOX;
}
/p\.?o\.?\s*box/i

p followed by optional period (\.?)
o followed by optional period
zero or more whitespace (\s*)
box
mine has the added advantage of matching po.box and po. box

-jsd-



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


Re: [PHP] Regular expression question

2003-08-04 Thread Jim Lucas
well, first off '' should not be allowed as a value of an attr= pair
anyways.

You should convert it to gt; or lt;

this will solve that problem.

Jim Lucas
- Original Message -
From: Dan Phiffer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, August 04, 2003 4:03 PM
Subject: [PHP] Regular expression question


 So I want to grab the attributes out of an HTML element. The following
 works, except in the case that the attribute's value includes the
character
 :

 if (preg_match_all(/tag([^]*)/i, $subject, $matches))
 print_r($matches);

 A $subject of tag attr=\value\ gives:

 Array
 (
 [0] = Array
 (
 [0] =
 )

 [1] = Array
 (
 [0] =  attr=value
 )

 )

 A $subject of tag attr=\\ gives:

 Array
 (
 [0] = Array
 (
 [0] =

 Thanks for any help,
 -Dan


 --
 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 expression question

2003-08-04 Thread Dan Phiffer
Actually, this is for a general purpose templating that might use  and  or
[ and ] (i.e. [element attribute=value]), but I suppose the same character
entity requirement could be applied to other boundary characters. Somehow
it didn't occur to me.

Thanks for the response,
-Dan

Jim Lucas [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 well, first off '' should not be allowed as a value of an attr= pair
 anyways.

 You should convert it to gt; or lt;

 this will solve that problem.

 Jim Lucas
 - Original Message -
 From: Dan Phiffer [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, August 04, 2003 4:03 PM
 Subject: [PHP] Regular expression question


  So I want to grab the attributes out of an HTML element. The following
  works, except in the case that the attribute's value includes the
 character
  :
 
  if (preg_match_all(/tag([^]*)/i, $subject, $matches))
  print_r($matches);
 
  A $subject of tag attr=\value\ gives:
 
  Array
  (
  [0] = Array
  (
  [0] =
  )
 
  [1] = Array
  (
  [0] =  attr=value
  )
 
  )
 
  A $subject of tag attr=\\ gives:
 
  Array
  (
  [0] = Array
  (
  [0] =
 
  Thanks for any help,
  -Dan
 
 
  --
  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 Expression

2003-08-04 Thread Curt Zirzow
* Thus wrote Ralph Guzman ([EMAIL PROTECTED]):
 Been working on this one for a while but can't get it working properly.
 I need a regular expression to match if address is 
 
 1. PO Box 
 2. P.O. Box
 3. P.O.Box
 
 I'm using /i to make this case insensitive.

/p\.?o\.?\s*box/i

 
 I got it working with 1  2, but it's still not matching 3. Any
 suggestions?
 
 if(preg_match( /p[\.]o\.* +box/i, trim($_POST['address'])){ 
echo Address is P.O. BOX;
 }

hmm.. if i read that right that will only match #2 (I'm not sure
that the [] includes a null match or not.) Also the character class
[] has special escapes, you dont need to escape the period because
the period is literal there. 

there are other alternatives people might also type like:

  p/o box

thus my original pattern becomes:

/p[.\\]?o\.?\s*box/i

 
HTH,

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



RE: [PHP] REGULAR EXPRESSION HELP

2003-07-14 Thread Ford, Mike [LSS]
 -Original Message-
 From: John [mailto:[EMAIL PROTECTED]
 Sent: 12 July 2003 07:31
 
 I need to match a pattern, not in a single-line but from a 
 HTML page, which
 obviously has loads of lines. I need to match 2 lines from 
 this HTML page:
 1) HTMLTITLEFirstVariable - Second Variable/TITLE/HTML
 2) TABLETDTR(newline)
 ThirdVariable/TR/TD/TABLE...
 
 I tried this code:
 1) preg_match(/HTMLTITLE(\S+) - (\S+)/TITLE/HTML/, 
 $html_page,
 $variables);
 2) preg_match(/TABLETDTR\n(\S+)/TR/TD/TABLE/, 
 $html_page,
 $variables);
 
 The first 2 variables are matched into the $variables array 
 but not the
 third one. Sometimes when the third one is matched, it starts 
 from where I
 want it to start but takes all the text to the end of the 
 HTML document!
 
 Any ideas? Is there any characters that I should have escaped that I
 didn't?? All I can think of is that because the first line 
 that I want to
 match is on the FIRST LINE of the html page, that matches. 
 But reg-ex can't
 handle the next line as its way down the page

Firstly, your newsline may actually be any of \n, \r, or \r\n according as
the file was built on a *nix, Mac or PC platform, so your regex should take
account of this.

Secondly, both of your examples should produce scads of errors attempting to
parse the regular expression, because you have unescaped slashes and your
delimiters are also slashes -- so either this is not a direct cut-and-paste
of what's actually in your script, or you're not letting on about something
else!  The fix for this one is either to escape the slashes that are
actually part of the match, or use something other than / as your delimiter.

Thirdly, as you've got double quotes around the regex, it would be advisable
to double the backslashes themselves (to ensure PHP doesn't attempt to
interpret any of its own backslash sequences) -- either that or use single
quotes to enclose the regex.

Fourthly, and perhaps most importantly, by default the * and + modifiers are
greedy -- that is, they match as much as possible consistent with the
whole match succeeding.  With your first match, this doesn't matter as
there's only one /TITLE in the document, so there's no ambiguity; with the
second match, there could be any number of occurrences of /TR/TD/TITLE
in the document, and the greedy matching of \S+ means that it will always be
the *last* of these that is found.  The way to counter this is to use one of
the ungreedy modifiers in your regex.

Taking all of these into account, you probably want something like:

preg_match('!TABLETDTR(\n|\r\n|\r)(\S+)/TR/TD/TABLE!U',
$html_page, $variables);

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

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



Re: [PHP] REGULAR EXPRESSION HELP

2003-07-12 Thread John W. Holmes
John wrote:
I need to match a pattern, not in a single-line but from a HTML page, which
obviously has loads of lines. I need to match 2 lines from this HTML page:
1) HTMLTITLEFirstVariable - Second Variable/TITLE/HTML
2) TABLETDTR(newline)
ThirdVariable/TR/TD/TABLE...
I tried this code:
1) preg_match(/HTMLTITLE(\S+) - (\S+)/TITLE/HTML/, $html_page,
$variables);
2) preg_match(/TABLETDTR\n(\S+)/TR/TD/TABLE/, $html_page,
$variables);
The first 2 variables are matched into the $variables array but not the
third one. Sometimes when the third one is matched, it starts from where I
want it to start but takes all the text to the end of the HTML document!
Your newline may be \r\n or \r instead of just \n.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals  www.phparch.com





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


<    1   2   3   4   >