Re: ereg / regexp fun

From: Date: Wed, 16 Aug 2000 18:10:26 +0000
Subject: Re: ereg / regexp fun
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-12082@lists.php.net to get a copy of this message
me@hansanderson.com ("Hans H. Anderson") writes: > Try ereg("( *:[a-z] *)",$msg,$item); > > On Wed, 16 Aug 2000, Dieter Kneffel wrote: > > > Ok, this clarifies a bit. But what if there is no space in front > > or after of my string but instead it is at the beginning or end > > of the line > > > > example: > > > > I need something that matches these cases. > > $msg = "command at the end of the line - :a"; > > $msg = ":a command at the beginning "; > > $msg = "command :a within my input"; > > $msg = ":a"; > > > > On the other hand, it should NOT match something like this: > > $msg = "hi:you!"; $msg =":aaabbb"; etc... ummm...that'll match the "hi:you!" string. $text = ":a I met:b a :c traveller :dfrom an antique land :e"; preg_match_all('/(?:^|\s):([a-z])\b/', $text, $matches); matches[1] would then contain array( 'a', 'c', 'e' ) -robin -- Robin Vickery............................................... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: robin@planet-three.net Phone: +44 (0)794 670 6395

« previous php.general (#12082) next »