【问题标题】:How can I detect the lines of code between the parentheses of this CREATE TABLE SQL?如何检测此 CREATE TABLE SQL 括号之间的代码行?
【发布时间】:2018-05-28 16:58:57
【问题描述】:

从下面的代码中,我只需要提取括号中的内容,而不使用这些。

create table if not exists `va_lottery`.`iso_4217`
(
    ccodealpha char(3) not null comment 'ISO alpha.',
    ccodenumeric char(3) not null comment 'ISO numeric',
    cminorunit varchar(4) default 0 comment 'Minor unit.',
    cname varchar(80) not null comment 'Name of the currency.',
    centity varchar(100) not null comment 'Entity.'
)
engine=innodb comment='ISO codes of coins.';

也就是说。只提取以下代码行。

    ccodealpha char(3) not null comment 'ISO alpha.',
    ccodenumeric char(3) not null comment 'ISO numeric',
    cminorunit varchar(4) default 0 comment 'Minor unit.',
    cname varchar(80) not null comment 'Name of the currency.',
    centity varchar(100) not null comment 'Entity.'

感谢您给予我的帮助。

【问题讨论】:

  • 正是我需要的,非常感谢。
  • 太好了,我已将其移至答案。请接受足够的测试。

标签: php regex regex-lookarounds regex-group


【解决方案1】:

假设您总是想在第一个和最后一个括号之间进行捕获,这将起作用:

(?s)\(\s*(.*)\s*\)

https://regex101.com/r/MVs17e/1/

(?s) 使. 匹配多行。 .* 是贪婪的并寻找最后一个 )。括号前的反斜杠转义括号,因为它们是正则表达式中的特殊字符。 \s* 是零个或多个空格,因此我们不会在封装括号之前/之后捕获空格。

【讨论】:

    猜你喜欢
    • 2016-04-24
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多