I am trying to match the first word and the parenthesis of column type definition.
Example input:
INTEGER NOT NULL
VARCHAR (255) NOT NULL
my regex is:
preg_match("/\s([\w]+)\s((\d+))/", $str, $match);
It works mostly fine for INTEGER, but for VARCHAR it is having 2 issues.
1. it matches 3 times, even though I have only specified 2 match areas (is it because of the * ?)
2. It matches the (255) for the first match. I thought \w would only match alpha and underscore.
Also, it matches INTEGER for the second match, and should match nothing.
Here's example output:
Array
(
[0] => INTEGER
[1] => INTEGER
)
Array
(
[0] => VARCHAR (255)
[1] => VARCHAR
[2] => (255)
)
I'm trying to get output like:
Array
(
[0] => VARCHAR
[1] => (255)
)Array
(
[0] => INTEGER
)