Re: [PHP] preg_match help please

2005-09-08 Thread Steve Turnbull
On Thu, 08 Sep 2005 16:36:36 +0100, Steve Turnbull wrote:

> On Thu, 08 Sep 2005 09:15:03 +0100, Steve Turnbull wrote:
> 
>> On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote:
>> 
>>> Steve Turnbull wrote:
 I am trying to find a regular expression to match a variable, what I think
 should work (but doesn't) is;
 
 preg_match ('^/[\w],[\w],/', $variable)
 
 The $variable MUST contain an alpha-numeric string, followed by a comma,
 followed by another alpha-numeric string, followed by another comma
 followed by (but doesn't have to!!) another alpha-numeric string followed
 by nothing.
 
 I realise my regex above doesn't allow for the last 'followed by nothing',
 but to me it looks like it should match the first part of the string up to
 the last comma?
>>> 
>>> Something like
>>> 
>>> '/^\w+,\w+,\w*$/'
>>> 
>>> maybe? (untested)
>>> 
>>> http://php.net/reference.pcre.pattern.syntax
>> 
>> Thats got me a lot further - thanks
>> 
>> I reduced it slightly to '/^\w+,\w+,' because at the end there is the
>> possibility of an alpha-numeric character(s) OR nothing at all with the
>> exception of a possible line break (note possible)
>> 
>> It's the 'possibly nothing at all' which I am slightly stuck on
>> 
>> Thanks
>> Steve
> 
> 
> One more thing (I have tried researching myself and reading the o'rielly
> book, but I need fairly swift solutions)...
> 
> How would I check for this scenario;
> 
> Two commas, which MAY have, but don't always have a value between, but
> the commas must ALWAYS be there - i.e.
> 
> var1,var2,var3
> var1,var2,
> var1,,
> 
No matter now - sorted. I hadn't read the final reply before I posted this
one

Thanks again

Steve

> Cheers
> Steve

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



Re: [PHP] preg_match help please

2005-09-08 Thread Steve Turnbull
On Thu, 08 Sep 2005 09:15:03 +0100, Steve Turnbull wrote:

> On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote:
> 
>> Steve Turnbull wrote:
>>> I am trying to find a regular expression to match a variable, what I think
>>> should work (but doesn't) is;
>>> 
>>> preg_match ('^/[\w],[\w],/', $variable)
>>> 
>>> The $variable MUST contain an alpha-numeric string, followed by a comma,
>>> followed by another alpha-numeric string, followed by another comma
>>> followed by (but doesn't have to!!) another alpha-numeric string followed
>>> by nothing.
>>> 
>>> I realise my regex above doesn't allow for the last 'followed by nothing',
>>> but to me it looks like it should match the first part of the string up to
>>> the last comma?
>> 
>> Something like
>> 
>> '/^\w+,\w+,\w*$/'
>> 
>> maybe? (untested)
>> 
>> http://php.net/reference.pcre.pattern.syntax
> 
> Thats got me a lot further - thanks
> 
> I reduced it slightly to '/^\w+,\w+,' because at the end there is the
> possibility of an alpha-numeric character(s) OR nothing at all with the
> exception of a possible line break (note possible)
> 
> It's the 'possibly nothing at all' which I am slightly stuck on
> 
> Thanks
> Steve


One more thing (I have tried researching myself and reading the o'rielly
book, but I need fairly swift solutions)...

How would I check for this scenario;

Two commas, which MAY have, but don't always have a value between, but
the commas must ALWAYS be there - i.e.

var1,var2,var3
var1,var2,
var1,,

Cheers
Steve

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



RE: [PHP] preg_match help please

2005-09-08 Thread Ford, Mike
On 08 September 2005 09:15, Steve Turnbull wrote:

> On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote:
> 
> > Steve Turnbull wrote:
> > > I am trying to find a regular expression to match a variable,
> > > what I think should work (but doesn't) is; 
> > > 
> > > preg_match ('^/[\w],[\w],/', $variable)
> > > 
> > > The $variable MUST contain an alpha-numeric string, followed by a
> > > comma, followed by another alpha-numeric string, followed by
> > > another comma followed by (but doesn't have to!!) another
> > > alpha-numeric string followed by nothing. 
> > > 
> > > I realise my regex above doesn't allow for the last 'followed by
> > > nothing', but to me it looks like it should match the first part
> > > of the string up to the last comma?
> > 
> > Something like
> > 
> > '/^\w+,\w+,\w*$/'
> > 
> > maybe? (untested)
> > 
> > http://php.net/reference.pcre.pattern.syntax
> 
> Thats got me a lot further - thanks
> 
> I reduced it slightly to '/^\w+,\w+,' because at the end there is the
> possibility of an alpha-numeric character(s) OR nothing at
> all with the
> exception of a possible line break (note possible)
> 
> It's the 'possibly nothing at all' which I am slightly stuck on

The * takes care of that -- it means 0 or more of the preceding entity.

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 


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] preg_match help please

2005-09-08 Thread Jasper Bryant-Greene

Steve Turnbull wrote:

On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote:


Something like

'/^\w+,\w+,\w*$/'

maybe? (untested)

http://php.net/reference.pcre.pattern.syntax



Thats got me a lot further - thanks

I reduced it slightly to '/^\w+,\w+,' because at the end there is the
possibility of an alpha-numeric character(s) OR nothing at all with the
exception of a possible line break (note possible)

It's the 'possibly nothing at all' which I am slightly stuck on


That's what the \w* means. That means "0 or more word-characters", as 
opposed to \w+ which means "1 or more word-characters. The $ after that 
means "end of string" which makes sure that it's the last thing in the 
string.


In other words, \w* means some word-characters, or nothing at all. You'd 
need to handle the newline in much the same way. The URL I gave you 
should help out a lot with that.


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

If you find my advice useful, please consider donating to a poor
student! You can choose whatever amount you think my advice was
worth to you. http://tinyurl.com/7oa5s

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



Re: [PHP] preg_match help please

2005-09-08 Thread Steve Turnbull
On Thu, 08 Sep 2005 19:27:49 +1200, Jasper Bryant-Greene wrote:

> Steve Turnbull wrote:
>> I am trying to find a regular expression to match a variable, what I think
>> should work (but doesn't) is;
>> 
>> preg_match ('^/[\w],[\w],/', $variable)
>> 
>> The $variable MUST contain an alpha-numeric string, followed by a comma,
>> followed by another alpha-numeric string, followed by another comma
>> followed by (but doesn't have to!!) another alpha-numeric string followed
>> by nothing.
>> 
>> I realise my regex above doesn't allow for the last 'followed by nothing',
>> but to me it looks like it should match the first part of the string up to
>> the last comma?
> 
> Something like
> 
> '/^\w+,\w+,\w*$/'
> 
> maybe? (untested)
> 
> http://php.net/reference.pcre.pattern.syntax

Thats got me a lot further - thanks

I reduced it slightly to '/^\w+,\w+,' because at the end there is the
possibility of an alpha-numeric character(s) OR nothing at all with the
exception of a possible line break (note possible)

It's the 'possibly nothing at all' which I am slightly stuck on

Thanks
Steve

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



Re: [PHP] preg_match help please

2005-09-08 Thread Jasper Bryant-Greene

Steve Turnbull wrote:

I am trying to find a regular expression to match a variable, what I think
should work (but doesn't) is;

preg_match ('^/[\w],[\w],/', $variable)

The $variable MUST contain an alpha-numeric string, followed by a comma,
followed by another alpha-numeric string, followed by another comma
followed by (but doesn't have to!!) another alpha-numeric string followed
by nothing.

I realise my regex above doesn't allow for the last 'followed by nothing',
but to me it looks like it should match the first part of the string up to
the last comma?


Something like

'/^\w+,\w+,\w*$/'

maybe? (untested)

http://php.net/reference.pcre.pattern.syntax

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

If you find my advice useful, please consider donating to a poor
student! You can choose whatever amount you think my advice was
worth to you. http://tinyurl.com/7oa5s

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



Re: [PHP] preg_match - help please

2005-07-28 Thread André Medeiros
On Thu, 2005-07-28 at 19:45 +0800, Jason Wong wrote:
> On Thursday 28 July 2005 01:50, André Medeiros wrote:
> 
> > You can have four words to describe a first and last name... you can
> > have other alphabets, like arabian, chinese, etc... inserting accented
> > characters alone would make that a big, nasty regex, let alone
> > predicting ways you can describe first/last names.
> >
> > I'm not saying that I have the _BEST_ sollution. All I'm saying is that
> > there are sittuations that are out of your control, and it seems to me
> > this might be the easiest way out, guaranteeing that there are at least
> > two words.
> 
> Most Chinese would enter their name (usually 3 words, sometimes 2. rarely 
> 4) WITHOUT any spaces.
> 
> Not sure what the OP was trying to do, but the best way to handle it 
> (IMHO) is to give the user 2 input boxes, one for  family name, the other 
> for the rest of their name.
> 
> -- 
> 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
> 

Heh... that's the best answer i've seen so far =)

That and the regexp's idea given by John (ie. forbid chars instead of
entering every letter of every alphabet) would work great.


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



Re: [PHP] preg_match - help please

2005-07-28 Thread Jason Wong
On Thursday 28 July 2005 01:50, André Medeiros wrote:

> You can have four words to describe a first and last name... you can
> have other alphabets, like arabian, chinese, etc... inserting accented
> characters alone would make that a big, nasty regex, let alone
> predicting ways you can describe first/last names.
>
> I'm not saying that I have the _BEST_ sollution. All I'm saying is that
> there are sittuations that are out of your control, and it seems to me
> this might be the easiest way out, guaranteeing that there are at least
> two words.

Most Chinese would enter their name (usually 3 words, sometimes 2. rarely 
4) WITHOUT any spaces.

Not sure what the OP was trying to do, but the best way to handle it 
(IMHO) is to give the user 2 input boxes, one for  family name, the other 
for the rest of their name.

-- 
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] preg_match - help please

2005-07-27 Thread John Nichel

André Medeiros wrote:

On Wed, 2005-07-27 at 12:30 -0400, John Nichel wrote:


André Medeiros wrote:


On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote:



André Medeiros wrote:



That's not very nice of you, saying that to people who try to help ;)

if( strpos( $_POST['frmName'], ' ' ) === false ) {
  // Do error handling here
} else {
  // All is OK :)
}



How does that match "Firstname Lastname" better than a regex?  That will 
return true as long as there is at least one space, no matter what the 
rest of the submission is.  I could submit "$^&#^&$&#& )([EMAIL PROTECTED]", or I 
could submit just a single space, and that would return true. strpos() 
has it's uses, but this isn't one of them.


There is a large number of sittuations that the regex won't work in.
Special characters aren't included (from what I can understand using my
weak regex knowlege), you could even be chinese, and it wouldn't work.

If you use strpos with trim and strlen cleverlly, you won't have to
worry about it again.

My $0.02


You can trim whitespace and check the length until the cows come home, 
and that still won't stop a string such as "#T*& [EMAIL PROTECTED]".  A regex can 
cover practicaly every situation for a name submission; it all depends 
on how deep you want to validate.  strpos() has too narrow of a scope to 
match a complex pattern.


You can have four words to describe a first and last name... you can
have other alphabets, like arabian, chinese, etc... inserting accented
characters alone would make that a big, nasty regex, let alone
predicting ways you can describe first/last names.


And this can all be matched with a regex.  Like I said, it depends on 
how deep you want to validate.



I'm not saying that I have the _BEST_ sollution. All I'm saying is that
there are sittuations that are out of your control, and it seems to me
this might be the easiest way out, guaranteeing that there are at least
two words. 


But it doesn't even guarantee that.  As shown previously, it will return 
true even on strings that have non-word characters in them (no matter 
the language).  The only thing you're guaranteeing with strpos ( 
$string, " " ); is that the string contains a space...that's it; and 
basically that's what you're limited too, until you start running other 
functions to check/remove other parts of the string



If you find a way to fit accented characters / other alphabets there
nicelly, be my guest :)


It's really quite easy, when you look at it from the other direction. 
When you're trying to match a pattern that can contain just about 
anything and be considered valid, it might be best to check for 
characters that you _do not_ want in there.  With that in mind, there's 
no reason to build a regex that can account for every possible alphabet 
and/or accents.  Make sure it contains a space, but doesn't contain 
characters we don't want (such as [EMAIL PROTECTED]).


--
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] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 12:30 -0400, John Nichel wrote:
> André Medeiros wrote:
> > On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote:
> > 
> >>André Medeiros wrote:
> >>
> >>>That's not very nice of you, saying that to people who try to help ;)
> >>>
> >>>if( strpos( $_POST['frmName'], ' ' ) === false ) {
> >>>// Do error handling here
> >>>} else {
> >>>// All is OK :)
> >>>}
> >>>
> >>
> >>How does that match "Firstname Lastname" better than a regex?  That will 
> >>return true as long as there is at least one space, no matter what the 
> >>rest of the submission is.  I could submit "$^&#^&$&#& )([EMAIL 
> >>PROTECTED]", or I 
> >>could submit just a single space, and that would return true. strpos() 
> >>has it's uses, but this isn't one of them.
> > 
> > There is a large number of sittuations that the regex won't work in.
> > Special characters aren't included (from what I can understand using my
> > weak regex knowlege), you could even be chinese, and it wouldn't work.
> > 
> > If you use strpos with trim and strlen cleverlly, you won't have to
> > worry about it again.
> > 
> > My $0.02
> 
> You can trim whitespace and check the length until the cows come home, 
> and that still won't stop a string such as "#T*& [EMAIL PROTECTED]".  A regex 
> can 
> cover practicaly every situation for a name submission; it all depends 
> on how deep you want to validate.  strpos() has too narrow of a scope to 
> match a complex pattern.
> 
> -- 
> John C. Nichel
> ÜberGeek
> KegWorks.com
> 716.856.9675
> [EMAIL PROTECTED]
> 

You can have four words to describe a first and last name... you can
have other alphabets, like arabian, chinese, etc... inserting accented
characters alone would make that a big, nasty regex, let alone
predicting ways you can describe first/last names.

I'm not saying that I have the _BEST_ sollution. All I'm saying is that
there are sittuations that are out of your control, and it seems to me
this might be the easiest way out, guaranteeing that there are at least
two words. 

If you find a way to fit accented characters / other alphabets there
nicelly, be my guest :)

Take care.

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



Re: [PHP] preg_match - help please

2005-07-27 Thread John Nichel

André Medeiros wrote:

On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote:


André Medeiros wrote:


That's not very nice of you, saying that to people who try to help ;)

if( strpos( $_POST['frmName'], ' ' ) === false ) {
   // Do error handling here
} else {
   // All is OK :)
}



How does that match "Firstname Lastname" better than a regex?  That will 
return true as long as there is at least one space, no matter what the 
rest of the submission is.  I could submit "$^&#^&$&#& )([EMAIL PROTECTED]", or I 
could submit just a single space, and that would return true. strpos() 
has it's uses, but this isn't one of them.


There is a large number of sittuations that the regex won't work in.
Special characters aren't included (from what I can understand using my
weak regex knowlege), you could even be chinese, and it wouldn't work.

If you use strpos with trim and strlen cleverlly, you won't have to
worry about it again.

My $0.02


You can trim whitespace and check the length until the cows come home, 
and that still won't stop a string such as "#T*& [EMAIL PROTECTED]".  A regex can 
cover practicaly every situation for a name submission; it all depends 
on how deep you want to validate.  strpos() has too narrow of a scope to 
match a complex pattern.


--
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] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 11:55 -0400, John Nichel wrote:
> André Medeiros wrote:
> > That's not very nice of you, saying that to people who try to help ;)
> > 
> > if( strpos( $_POST['frmName'], ' ' ) === false ) {
> > // Do error handling here
> > } else {
> > // All is OK :)
> > }
> > 
> 
> How does that match "Firstname Lastname" better than a regex?  That will 
> return true as long as there is at least one space, no matter what the 
> rest of the submission is.  I could submit "$^&#^&$&#& )([EMAIL PROTECTED]", 
> or I 
> could submit just a single space, and that would return true. strpos() 
> has it's uses, but this isn't one of them.
> 
> -- 
> John C. Nichel
> ÜberGeek
> KegWorks.com
> 716.856.9675
> [EMAIL PROTECTED]
> 

There is a large number of sittuations that the regex won't work in.
Special characters aren't included (from what I can understand using my
weak regex knowlege), you could even be chinese, and it wouldn't work.

If you use strpos with trim and strlen cleverlly, you won't have to
worry about it again.

My $0.02

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



RE: [PHP] preg_match - help please

2005-07-27 Thread Mike Johnson
From: André Medeiros [mailto:[EMAIL PROTECTED] 

> On Wed, 2005-07-27 at 11:41 -0400, Mike Johnson wrote:
> > From: André Medeiros [mailto:[EMAIL PROTECTED] 
> > 
> > > On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote:
> > > 
> > > > Or even four - like Rafael van der Vaart for example - so 
> > > make sure that the
> > > > surname box matches spaces as well, and special characters 
> > > like the ê, as
> > > > well as ' as in John O'Kane
> > > > 
> > > 
> > > Yeah, that's why strpos will make his life much easier :)
> > 
> > Can you explain how you'd use strpos() in this situation? I 
> was going to ask earlier, but didn't bother, but now I'm curious...
> > 
> 
> That's not very nice of you, saying that to people who try to help ;)

Well, it could be argued that an obtuse link to the online docs and nothing 
else isn't "trying to help."   ;)

> if( strpos( $_POST['frmName'], ' ' ) === false ) {
> // Do error handling here
> } else {
> // All is OK :)
> }

Gotcha. Except that it'll accept a ' ' string as valid.   :P

-- 
Mike Johnson Smarter Living, Inc.
Web Developerwww.smartertravel.com
[EMAIL PROTECTED]   (617) 886-5539

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



Re: [PHP] preg_match - help please

2005-07-27 Thread John Nichel

André Medeiros wrote:

That's not very nice of you, saying that to people who try to help ;)

if( strpos( $_POST['frmName'], ' ' ) === false ) {
// Do error handling here
} else {
// All is OK :)
}



How does that match "Firstname Lastname" better than a regex?  That will 
return true as long as there is at least one space, no matter what the 
rest of the submission is.  I could submit "$^&#^&$&#& )([EMAIL PROTECTED]", or I 
could submit just a single space, and that would return true. strpos() 
has it's uses, but this isn't one of them.


--
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] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 11:41 -0400, Mike Johnson wrote:
> From: André Medeiros [mailto:[EMAIL PROTECTED] 
> 
> > On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote:
> > 
> > > Or even four - like Rafael van der Vaart for example - so 
> > make sure that the
> > > surname box matches spaces as well, and special characters 
> > like the ê, as
> > > well as ' as in John O'Kane
> > > 
> > 
> > Yeah, that's why strpos will make his life much easier :)
> 
> Can you explain how you'd use strpos() in this situation? I was going to ask 
> earlier, but didn't bother, but now I'm curious...
> 

That's not very nice of you, saying that to people who try to help ;)

if( strpos( $_POST['frmName'], ' ' ) === false ) {
// Do error handling here
} else {
// All is OK :)
}

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



RE: [PHP] preg_match - help please

2005-07-27 Thread Mike Johnson
From: André Medeiros [mailto:[EMAIL PROTECTED] 

> On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote:
> 
> > Or even four - like Rafael van der Vaart for example - so 
> make sure that the
> > surname box matches spaces as well, and special characters 
> like the ê, as
> > well as ' as in John O'Kane
> > 
> 
> Yeah, that's why strpos will make his life much easier :)

Can you explain how you'd use strpos() in this situation? I was going to ask 
earlier, but didn't bother, but now I'm curious...

-- 
Mike Johnson Smarter Living, Inc.
Web Developerwww.smartertravel.com
[EMAIL PROTECTED]   (617) 886-5539

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



Re: [PHP] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 16:16 +0100, Mark Rees wrote:
> "André Medeiros" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote:
> > > Hi
> > >
> > > I want to see that a user is submiting a form field in the correct
> manner.
> > > So I decided to use preg_match to verify their input.
> > >
> > > The pattern I am trying to match is;
> > >
> > > Firstname Secondname
> > >
> > > I am not bothered about character length just yet (but advise on this
> would
> > > be appreciated if it can be done with a regular expression - saves extra
> > > checking code), but I would like case sensitity.
> > >
> > > The code I haev so far, which doesn't seem to work is;
> > >
> > > $un = $_REQUEST['name'];
> > > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/';
> > >
> > > if (preg_match($exp, $un)) {
> > > //has this matched?
> > > echo "matched";
> > > }
> > >
> > > Help would be greatly appreciated
> > >
> > > Thanks
> > > Steve
> > >
> >
> > A reminder... sometimes First and Last name can contain three words.
> > There are portuguese names, like "Inês de Medeiros". Watch out for that
> > too.
> 
> Or even four - like Rafael van der Vaart for example - so make sure that the
> surname box matches spaces as well, and special characters like the ê, as
> well as ' as in John O'Kane
> 

Yeah, that's why strpos will make his life much easier :)

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



Re: [PHP] preg_match - help please

2005-07-27 Thread Mark Rees
"André Medeiros" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote:
> > Hi
> >
> > I want to see that a user is submiting a form field in the correct
manner.
> > So I decided to use preg_match to verify their input.
> >
> > The pattern I am trying to match is;
> >
> > Firstname Secondname
> >
> > I am not bothered about character length just yet (but advise on this
would
> > be appreciated if it can be done with a regular expression - saves extra
> > checking code), but I would like case sensitity.
> >
> > The code I haev so far, which doesn't seem to work is;
> >
> > $un = $_REQUEST['name'];
> > $exp = '/^\b[a-zA-Z] [a-zA-Z]$/';
> >
> > if (preg_match($exp, $un)) {
> > //has this matched?
> > echo "matched";
> > }
> >
> > Help would be greatly appreciated
> >
> > Thanks
> > Steve
> >
>
> A reminder... sometimes First and Last name can contain three words.
> There are portuguese names, like "Inês de Medeiros". Watch out for that
> too.

Or even four - like Rafael van der Vaart for example - so make sure that the
surname box matches spaces as well, and special characters like the ê, as
well as ' as in John O'Kane

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



Re: [PHP] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote:
> Hi
> 
> I want to see that a user is submiting a form field in the correct manner.
> So I decided to use preg_match to verify their input.
> 
> The pattern I am trying to match is;
> 
> Firstname Secondname
> 
> I am not bothered about character length just yet (but advise on this would
> be appreciated if it can be done with a regular expression - saves extra
> checking code), but I would like case sensitity.
> 
> The code I haev so far, which doesn't seem to work is;
> 
> $un = $_REQUEST['name'];
> $exp = '/^\b[a-zA-Z] [a-zA-Z]$/';
> 
> if (preg_match($exp, $un)) {
> //has this matched?
> echo "matched";
> }
> 
> Help would be greatly appreciated
> 
> Thanks
> Steve
> 

A reminder... sometimes First and Last name can contain three words.
There are portuguese names, like "Inês de Medeiros". Watch out for that
too.

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



Re: [PHP] preg_match - help please

2005-07-27 Thread André Medeiros
On Wed, 2005-07-27 at 15:27 +0100, Steve Turnbull wrote:
> Hi
> 
> I want to see that a user is submiting a form field in the correct manner.
> So I decided to use preg_match to verify their input.
> 
> The pattern I am trying to match is;
> 
> Firstname Secondname
> 
> I am not bothered about character length just yet (but advise on this would
> be appreciated if it can be done with a regular expression - saves extra
> checking code), but I would like case sensitity.
> 
> The code I haev so far, which doesn't seem to work is;
> 
> $un = $_REQUEST['name'];
> $exp = '/^\b[a-zA-Z] [a-zA-Z]$/';
> 
> if (preg_match($exp, $un)) {
> //has this matched?
> echo "matched";
> }
> 
> Help would be greatly appreciated
> 
> Thanks
> Steve
> 

http://pt.php.net/strpos

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



Re: [PHP] preg_match - help please

2005-07-27 Thread John Nichel

Steve Turnbull wrote:

Hi

I want to see that a user is submiting a form field in the correct manner.
So I decided to use preg_match to verify their input.

The pattern I am trying to match is;

Firstname Secondname

I am not bothered about character length just yet (but advise on this would
be appreciated if it can be done with a regular expression - saves extra
checking code), but I would like case sensitity.

The code I haev so far, which doesn't seem to work is;

$un = $_REQUEST['name'];
$exp = '/^\b[a-zA-Z] [a-zA-Z]$/';

if (preg_match($exp, $un)) {
//has this matched?
echo "matched";
}

Help would be greatly appreciated


/^[a-zA-Z]{1,}\s[a-zA-Z]{1,}$/

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Preg_match----------help

2005-01-22 Thread RaTT
Hello, 

This regular expresion should help you on your way 

$regex = "/<[A-z_\-]+>?/";

HTH 
Jarratt

On Sat, 22 Jan 2005 17:03:30 +0600, Chandana Bandara
<[EMAIL PROTECTED]> wrote:
> hi ,
> 
> using preg_match , how can i match "<", "_" , ">" " - " such special 
> characters in a sentence  ???
> 
> Eg:
> 
> Strings are like this,
> 
> 1.Ahgrwgsgd dfjb yuhh dfh  to match   
> 2.AFRYRGH  vhGHJGB  GHJGJ  kjHGKJGK -- here i want to 
> match  
> 
> 3.GHHTGH GHJK  
> what is the most suitable way to match those data ? plz guide me ,
> 
> Thanx in advance,
> chandana
> 
>

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



Re: [PHP] preg_match help?

2002-08-17 Thread Jason Wong

On Sunday 18 August 2002 08:29, vic wrote:
> Ok, since I've been trying to get this working forever, how wold you get
> something like this working I need, to get everything between these 2
> tags:
>
>  and 
>
> Someone gave me this code:
>
> preg_match('!]+>(.*)!Uis',$str,$regs);
>
> with the ! in front, and !Uis at the end, what does that mean?

It's good that someone else does the work for, but it's also good to read the 
documentation as well. All these regexes has what is called a delimiter, 
everything that is enclosed within the delimiter is the expression. In most 
cases the '/' is used as the delimiter. But if you're trying to match '/' in 
your expression (as in your case you're looking for ) then it makes 
sense to use a different delimiter, one that ideally is not used in your 
expression. Thus the above use of '!'. The 'Uis' are modifiers and modify 
matching behaviour (rtfm).


> And when i try it with your script:
>
> preg_match('/.*]+>(.*).*/',$str,$regs);
> $good = $regs[1];
> echo $good;
>
>
> I get:
>
> Warning: Unknown modifier 'd' in
> /home/victor/argilent-www/sites/malibu_place_2/main.php on line 197

Hopefully from the above explanation you can see that:

  /.*]+>(.*).*/'

here you're using '/' as the delimiter. Thus everything between the first 2 
'/' is the expression, ie:

  .*]+>(.*)<

Whatever is after the 2nd '/' is treated as a modifier, and hence your 
warning, unknown modifier.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
What the scientists have in their briefcases is terrifying.
-- Nikita Khruschev
*/


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




RE: [PHP] preg_match help?

2002-08-17 Thread vic

 Actually I made a mistake, I get nothing, which might mean that I am
looking for the wrong thing in ereg preg match, or I don't know ,much
about reg exp and that space is throwing it off 

I dunno.. 

- Vic


-Original Message-
From: vic [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, August 17, 2002 8:30 PM
To: [EMAIL PROTECTED]; 'Jason Soza'; 'PHP-General'
Subject: RE: [PHP] preg_match help?

Ok, since I've been trying to get this working forever, how wold you get
something like this working I need, to get everything between these 2
tags:

 and 

Someone gave me this code:

preg_match('!]+>(.*)!Uis',$str,$regs);

with the ! in front, and !Uis at the end, what does that mean? 

And when i try it with your script:

preg_match('/.*]+>(.*).*/',$str,$regs);
$good = $regs[1];
echo $good;


I get:

Warning: Unknown modifier 'd' in
/home/victor/argilent-www/sites/malibu_place_2/main.php on line 197

197 is the preg_match code line.

- Vic


-Original Message-
From: Bas Jobsen [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, August 17, 2002 6:49 PM
To: Jason Soza; PHP-General
Subject: Re: [PHP] preg_match help?

preg_match("/.*]+>(.*).*/", 
$contents,$story);
echo $story[1];

preg_match always return a array. The first element ($array[0])contains
your 
complete regexp. The next ($array[1])one the first match between () etc.
Don't use ! but /




Op zondag 18 augustus 2002 01:27, schreef Jason Soza:
> I seriously need some help trying to make a match here. Obligatory
> disclaimer: yes, I've searched google.com, I've read the PHP manual
section
> on preg_match(), and I've sat here for 3 hours trying to resolve this
on my
> own. :) Any help would be great:
>
> I need to match everything between:
>
> $headline
>
> Where $headline is a variable that will be filled out of a foreach()
loop.
> The pattern should return everything until it hits:
>
> 
>
> The text file this is taken out of looks like:
>
> Headline here
>
> News story, blah, blah, blah...
>
> Another headline
>
> More news, blah, blah...
>
> ...
>
> The contents of the text file echo correctly before the preg_match,
but the
> preg_match I've tried:
>
> preg_match("!]+>(.*)!",
$contents,
> $story);
>
> Returns array(), so no matches are made. Any suggestions?
>
> TIA,
>
> Jason Soza

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

__ 
Post your ad for free now! http://personals.yahoo.ca

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

__ 
Post your ad for free now! http://personals.yahoo.ca

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




RE: [PHP] preg_match help?

2002-08-17 Thread vic

Ok, since I've been trying to get this working forever, how wold you get
something like this working I need, to get everything between these 2
tags:

 and 

Someone gave me this code:

preg_match('!]+>(.*)!Uis',$str,$regs);

with the ! in front, and !Uis at the end, what does that mean? 

And when i try it with your script:

preg_match('/.*]+>(.*).*/',$str,$regs);
$good = $regs[1];
echo $good;


I get:

Warning: Unknown modifier 'd' in
/home/victor/argilent-www/sites/malibu_place_2/main.php on line 197

197 is the preg_match code line.

- Vic


-Original Message-
From: Bas Jobsen [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, August 17, 2002 6:49 PM
To: Jason Soza; PHP-General
Subject: Re: [PHP] preg_match help?

preg_match("/.*]+>(.*).*/", 
$contents,$story);
echo $story[1];

preg_match always return a array. The first element ($array[0])contains
your 
complete regexp. The next ($array[1])one the first match between () etc.
Don't use ! but /




Op zondag 18 augustus 2002 01:27, schreef Jason Soza:
> I seriously need some help trying to make a match here. Obligatory
> disclaimer: yes, I've searched google.com, I've read the PHP manual
section
> on preg_match(), and I've sat here for 3 hours trying to resolve this
on my
> own. :) Any help would be great:
>
> I need to match everything between:
>
> $headline
>
> Where $headline is a variable that will be filled out of a foreach()
loop.
> The pattern should return everything until it hits:
>
> 
>
> The text file this is taken out of looks like:
>
> Headline here
>
> News story, blah, blah, blah...
>
> Another headline
>
> More news, blah, blah...
>
> ...
>
> The contents of the text file echo correctly before the preg_match,
but the
> preg_match I've tried:
>
> preg_match("!]+>(.*)!",
$contents,
> $story);
>
> Returns array(), so no matches are made. Any suggestions?
>
> TIA,
>
> Jason Soza

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

__ 
Post your ad for free now! http://personals.yahoo.ca

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




Re: [PHP] preg_match help?

2002-08-17 Thread Bas Jobsen

preg_match("/.*]+>(.*).*/", 
$contents,$story);
echo $story[1];

preg_match always return a array. The first element ($array[0])contains your 
complete regexp. The next ($array[1])one the first match between () etc.
Don't use ! but /




Op zondag 18 augustus 2002 01:27, schreef Jason Soza:
> I seriously need some help trying to make a match here. Obligatory
> disclaimer: yes, I've searched google.com, I've read the PHP manual section
> on preg_match(), and I've sat here for 3 hours trying to resolve this on my
> own. :) Any help would be great:
>
> I need to match everything between:
>
> $headline
>
> Where $headline is a variable that will be filled out of a foreach() loop.
> The pattern should return everything until it hits:
>
> 
>
> The text file this is taken out of looks like:
>
> Headline here
>
> News story, blah, blah, blah...
>
> Another headline
>
> More news, blah, blah...
>
> ...
>
> The contents of the text file echo correctly before the preg_match, but the
> preg_match I've tried:
>
> preg_match("!]+>(.*)!", $contents,
> $story);
>
> Returns array(), so no matches are made. Any suggestions?
>
> TIA,
>
> Jason Soza

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