Re: ereg / regexp fun

From: Date: Wed, 16 Aug 2000 15:06:40 +0000
Subject: Re: ereg / regexp fun
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12045@lists.php.net to get a copy of this message
Dieter, First off, is it possible to just use the normal $variable and eval() to parse the string. It might be easier and it would surely be more efficient. Anyway, if not, your regex: > if(ereg("[^ ]+:([a-z]{1})[ $]+",$msg,$item)){ > ... > } Looks like it will match "any character that isn't a space from 1 character to infinity, then a : character, then any lower case alpha character from once to infinity ({1} = +, you want {,1} or {1,1} or just plain nothing), then either a space or a dollar sign from 1 to infinity." Here's one that might be more effective: ereg(" (:[a-z]) ",$msg,$item) That says "match a space followed by a : followed by any lower case alpha character once followed by a space", which is what you want, if I follow correctly. Hans On Wed, 16 Aug 2000, Dieter Kneffel wrote: > > I need to trigger some functions when a user enters a command like ':a' > or ':b' > The command is embedded within $msg; e.g. $msg = 'see :a for info' > Where > the :a will be replaced e.g. by an image... > > see this: > --------- > if(ereg("[^ ]+:([a-z]{1})[ $]+",$msg,$item)){ > ... > } > --------- > > This already works almost. but it matches also unwanted cases, e.g. if > $msg = 'aaaaa:bbbbcccc' > > What is the correct regexp that matches a blank or the beginning of a > string? > What is the correct regexp that matches a blank or the end of a string? Hans Anderson ~ me@hansanderson.com PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia, http://www.hansanderson.com | Killer Audio Production, http://www.goofiness.com | Minty Fresh Breath.

« previous php.general (#12045) next »