RE: preg_match help please

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: m.ford@xxxxxxxxxxxxxx
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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux