Re: Regexp trouble

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

 



Andy Pieters wrote:
> Hi list
> 
> I still fail to understand why regular expressions are causing me such a hard 
> time.
> 
> <snip />

Hi!

Why don't you use 'preg_match'? And why do you use all those character
classes?


This:

<code>
	$subject = 'Nov 22 06:51:36';
	$pattern = '/^(\w{3})\s(\d{2})\s(\d{2}):(\d{2}):(\d{2})/';
	if (preg_match($pattern, $subject, $matches)) {
		print_r($matches);
	}
</code>


nicely prints:

Array
(
    [0] => Nov 22 06:51:36
    [1] => Nov
    [2] => 22
    [3] => 06
    [4] => 51
    [5] => 36
)


Bye
Frank

-- 
tradeOver | http://www.tradeover.net
...ready to become the King of the World?

-- 
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