首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php regex匹配mysql数据类型

php regex匹配mysql数据类型
EN

Stack Overflow用户
提问于 2013-07-30 19:30:02
回答 1查看 637关注 0票数 0

php regex匹配mysql数据类型,使用所有mysql数据类型作为主体,即

代码语言:javascript
复制
int(5)
varchar(10)
enum('yes', 'no')

我需要这样的数组:

代码语言:javascript
复制
array( 'int', 5 )
array( 'varchar', 10 )
array( 'enum', 'yes', 'no' )    or    array ('enum', array('yes', 'no'))

到目前为止,我可以将括号的内容与以下内容匹配:

代码语言:javascript
复制
/\(([^)]+)\)$/   and with    /\((.*)?\)/

我需要的是:

代码语言:javascript
复制
number 1 - everything before the first opening parentheses

number 2 - everything inside the parentheses pair but not matching the parenthesis

number 3 - match the contents of the enum data type and return it's individual values (when values are delimited by "'" or by '"' or not delimited at all)

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-30 19:46:12

代码语言:javascript
复制
/([a-zA-Z\s]*)\((.*)\)$/

([a-zA-Z\s]*) -匹配零或多个字母或空格

(-匹配开始括号(.*) -匹配任何字符串)$ -匹配行尾的结束括号

PHP:

代码语言:javascript
复制
preg_match ('/([a-zA-Z\s]*)\((.*)\)$/', $your_string, $matches);
$matches[1] -> Type int, enum, etc.
$matches[2] -> Size 10, (yes, no), ..
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17955744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档