Re: RegOops

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

 



> 23 okt 2015 kl. 14:44 skrev Karl DeSaulniers <karl@xxxxxxxxxxxxxxx>:
> 
> Hello all,
> With the given string..  
> 
> vehicle10-vehicle-name
> 
> Running regex in a preg_match like
> 
> "/(\w+)([0-9+]+)-(.*)/"
> 
> I am getting.
> 
> array(
> 	0	=>	vehicle10-vehicle-name
> 	1	=>	vehicle1
> 	2	=>	0
> 	3	=>	vehicle-name
> )
> 
> If I change it to.
> 
> "/(\D+)([0-9+]+)-(.*)/"
> 
> it works as expected.
> 
> array(
> 	0	=>	vehicle10-vehicle-name
> 	1	=>	vehicle
> 	2	=>	10
> 	3	=>	vehicle-name
> )
> 
> Why is the \w directive including a digit?
> Since when is the number 1 a word??
> 
> If anyone could enlighten me, I would greatly appreciate it.
> 
> TIA
> 
> Best,
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 

Hi Karl!

I am not able to pinpoint the exact definition in the official PCRE documentation right now (http://www.pcre.org). But the short hand \w does in deed include numbers. As you can read here for example (https://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html), 

\w	A word character: [a-zA-Z_0-9]

Although its already Friday, your pattern is working as expected.

/frank


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