Re: [PHP] regular expression question

2007-09-01 Thread Richard Heyes
But how? The +[a-z]{2,} seems to allow at least two a-z clusters, but it 
doesn't include a period. /ml


Almost correct. The plus belongs to whatever comes before it, not after. 
So what you're referring to as matching two or more characters but not 
the period, is this:


[a-z]{2,}

And this will match one or more  "subdomains":

([-a-z0-9]+\.)+

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

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



Re: [PHP] regular expression question

2007-08-31 Thread Per Jessen
Matthew Lasar wrote:

> At 11:32 AM 8/31/2007, Per Jessen wrote:
>>Matthew Lasar wrote:
>>
>> > But I don't understand why the second half of the regular
>> > expression works. I'm talking about this part:
>> >
>> > @([-a-z0-9]+\.)+[a-z]{2,}/";
>> >
>> > why is it able to detect repeated sections of the email address
>> > after "@" that are separated by periods? like "@email.alaska.com" .
>> > It looks to me like it's only looking for one example of that
>> > pattern. Does the "()" allow an unlimited number of patterns to
>> > pass?
>>
>>No, but the following '+' does.
> 
> But how? The +[a-z]{2,} seems to allow at least
> two a-z clusters, but it doesn't include a period. /ml
> 

That plus applies to the grouping () before it:

([-a-z0-9]+\.)+   one or more sequences of -a-z0-9 followed by a period



/Per Jessen, Zürich

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



Re: [PHP] regular expression question

2007-08-31 Thread Matthew Lasar

At 11:32 AM 8/31/2007, Per Jessen wrote:

Matthew Lasar wrote:

> But I don't understand why the second half of the regular expression
> works. I'm talking about this part:
>
> @([-a-z0-9]+\.)+[a-z]{2,}/";
>
> why is it able to detect repeated sections of the email address after
> "@" that are separated by periods? like "@email.alaska.com" . It
> looks to me like it's only looking for one example of that pattern.
> Does the "()" allow an unlimited number of patterns to pass?

No, but the following '+' does.


But how? The +[a-z]{2,} seems to allow at least 
two a-z clusters, but it doesn't include a period. /ml




/Per Jessen, Zürich

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.484 / Virus Database: 269.13.0/980 
- Release Date: 8/30/2007 6:05 PM


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



Re: [PHP] regular expression question

2007-08-31 Thread Per Jessen
Matthew Lasar wrote:

> But I don't understand why the second half of the regular expression
> works. I'm talking about this part:
> 
> @([-a-z0-9]+\.)+[a-z]{2,}/";
> 
> why is it able to detect repeated sections of the email address after
> "@" that are separated by periods? like "@email.alaska.com" . It
> looks to me like it's only looking for one example of that pattern.
> Does the "()" allow an unlimited number of patterns to pass?

No, but the following '+' does. 


/Per Jessen, Zürich

--
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
/(?<=(?  $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 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,
> 
> 
> $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"
> );



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

> 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 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,
>
> 
> $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";
> 
>
>
> 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

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 = '
 /
(?
- 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 
--
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 = '
 /
(?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 > or <
>
> 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("/]*)>/i", $subject, $matches))
> > print_r($matches);
> >
> > A $subject of "" gives:
> >
> > Array
> > (
> > [0] => Array
> > (
> > [0] =>
> > )
> >
> > [1] => Array
> > (
> > [0] =>  attr="value"
> > )
> >
> > )
> >
> > A $subject of "\">" 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 Jim Lucas
well, first off '>' should not be allowed as a value of an attr="" pair
anyways.

You should convert it to > or <

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("/]*)>/i", $subject, $matches))
> print_r($matches);
>
> A $subject of "" gives:
>
> Array
> (
> [0] => Array
> (
> [0] =>
> )
>
> [1] => Array
> (
> [0] =>  attr="value"
> )
>
> )
>
> A $subject of "\">" 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

2002-11-01 Thread John Nichel
It might, you should test it to find out.

John Meyer wrote:

I've got a regexp:

(EV[0-9]{2})!([0-9]{4}-[0-9]{2}-[0-9]{2})!(GR[0-9]{2}).txt


My question is, will it match this:


EV01!2002-11-09!VR01!GR01.txt



And anything formatted like this: (EV02, and so forth).





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




Re: [PHP] Regular expression question

2001-11-09 Thread Jack Dempsey

What is $num going to be? A number? So how do you determine where that
number ends and where there shouldn't be another number in front of it...are
there any restrictions on the size of $num?

say $num is 51
then you're saying that you want to match
51::
but not 151::
however, what if $num is 151? see what i mean?
- Original Message -
From: "Leon Mergen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, November 09, 2001 1:53 PM
Subject: [PHP] Regular expression question


> Hello,
>
> I have a little question regarding regular expressions... I want to check
> for the pattern
>
> $num::
>
> But, $num may not be started with another number (assume the number will
be
> 51 , 1 will also match (the pattern 1:: is available in 51::) ...
Currently,
> my regular expression is:
>
> eregi("([^0-9]$num::)", $string);
>
> But that doesn't seem to work... The other option, the start of a line or
a
> : also didn't work:
>
> eregi("([^|:]$sess_id::)", $string);
>
> Anyone can help me with this?
>
> Thanks in advance,
>
> Leon Mergen
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regular Expression Question

2001-07-25 Thread Matthew Loff


http://www.php.net/manual/en/function.substr.php

string substr (string string, int start [, int length])

Substr returns the portion of string specified by the start and length
parameters. 

If start is positive, the returned string will start at the start'th
position in string, counting from zero. For instance, in the string
'abcdef', the character at position 0 is 'a', the character at position
2 is 'c', and so forth. 

Examples: 
$rest = substr ("abcdef", 1);// returns "bcdef"
$rest = substr ("abcdef", 1, 3); // returns "bcd"


-Original Message-
From: Seb Frost [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, July 25, 2001 5:09 PM
To: [EMAIL PROTECTED]; PHP
Subject: RE: [PHP] Regular Expression Question


I hope my later message clarifys what I mean.

- seb

-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 22:05
To: PHP
Subject: RE: [PHP] Regular Expression Question


Aren't the trims just for white space?
Jeff Oien

> since you know exactly which 4 characters you want to keep you can use

> a simple string trimming routine.  I forget the name of the function 
> in php but it's there and it'll be something like
>
> trimstring($string,1,5);
>
> or something like that.  No need for complicated regular expressions
either
> way.
>
> - seb
>
> -Original Message-
> From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> Sent: 25 July 2001 21:47
> To: PHP
> Subject: [PHP] Regular Expression Question
>
>
> I want to replace a string like this 1B335-2G with this B335. So for 
> all
the
> strings I want to remove the first character and the last three
characters.
> I'm not sure which replace function to use or how to go about it. 
> Thanks. Jeff Oien
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED] To 
> contact the list administrators, e-mail: [EMAIL PROTECTED]
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regular Expression Question

2001-07-25 Thread Seb Frost

I hope my later message clarifys what I mean.

- seb

-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 22:05
To: PHP
Subject: RE: [PHP] Regular Expression Question


Aren't the trims just for white space?
Jeff Oien

> since you know exactly which 4 characters you want to keep you can use a
> simple string trimming routine.  I forget the name of the function in php
> but it's there and it'll be something like
>
> trimstring($string,1,5);
>
> or something like that.  No need for complicated regular expressions
either
> way.
>
> - seb
>
> -Original Message-
> From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> Sent: 25 July 2001 21:47
> To: PHP
> Subject: [PHP] Regular Expression Question
>
>
> I want to replace a string like this 1B335-2G with this B335. So for all
the
> strings I want to remove the first character and the last three
characters.
> I'm not sure which replace function to use or how to go about it. Thanks.
> Jeff Oien
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regular Expression Question

2001-07-25 Thread Jeff Oien

Aren't the trims just for white space?
Jeff Oien

> since you know exactly which 4 characters you want to keep you can use a
> simple string trimming routine.  I forget the name of the function in php
> but it's there and it'll be something like
> 
> trimstring($string,1,5);
> 
> or something like that.  No need for complicated regular expressions either
> way.
> 
> - seb
> 
> -Original Message-
> From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> Sent: 25 July 2001 21:47
> To: PHP
> Subject: [PHP] Regular Expression Question
> 
> 
> I want to replace a string like this 1B335-2G with this B335. So for all the
> strings I want to remove the first character and the last three characters.
> I'm not sure which replace function to use or how to go about it. Thanks.
> Jeff Oien
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regular Expression Question correction

2001-07-25 Thread Seb Frost

$newstring = substr($string,1,4);

FOUR, not FIVE.  Doh.

-Original Message-
From: Seb Frost [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 22:03
To: [EMAIL PROTECTED]; PHP
Subject: RE: [PHP] Regular Expression Question


since you know exactly which 4 characters you want to keep you can use a
simple string trimming routine.

$newstring = substr($string,1,5);

No need for complicated regular expressions!

- seb

-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 21:47
To: PHP
Subject: [PHP] Regular Expression Question


I want to replace a string like this 1B335-2G with this B335. So for all the
strings I want to remove the first character and the last three characters.
I'm not sure which replace function to use or how to go about it. Thanks.
Jeff Oien

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regular Expression Question

2001-07-25 Thread Seb Frost

since you know exactly which 4 characters you want to keep you can use a
simple string trimming routine.

$newstring = substr($string,1,5);

No need for complicated regular expressions!

- seb

-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 21:47
To: PHP
Subject: [PHP] Regular Expression Question


I want to replace a string like this 1B335-2G with this B335. So for all the
strings I want to remove the first character and the last three characters.
I'm not sure which replace function to use or how to go about it. Thanks.
Jeff Oien

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]