开发者社区 问答 正文

将带注释的多行(自由空间)正则表达式传递给preg_match

我有一个正则表达式,它最终会有点长,并且使跨多行阅读更容易。

preg_match(
    '^J[0-9]{7}:\s+
    (.*?)             #Extract the Transaction Start Date msg
    \s+J[0-9]{7}:\s+Project\sname:\s+
    (.*?)             #Extract the Project Name
    \s+J[0-9]{7}:\s+Job\sname:\s+
    (.*?)             #Extract the Job Name
    \s+J[0-9]{7}:\s+',
    $this->getResultVar('FullMessage'),
    $atmp
);

有没有办法将上述形式的正则表达式传递给preg_match?

展开
收起
游客ufivfoddcd53c 2020-01-03 20:56:38 772 分享 版权
1 条回答
写回答
取消 提交回答
  • 您可以使用扩展语法:

    preg_match("/
        test
    /x", $foo, $bar);
    
    2020-01-03 20:56:56
    赞同 展开评论