【发布时间】:2014-01-23 15:51:42
【问题描述】:
我有这段文字
CREATE TABLE IF NOT EXISTS `arrivals` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`jobid` int(11) NOT NULL,
`eta` int(32) NOT NULL,
`keyword` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`searchengine` varchar(3) NOT NULL DEFAULT 'de' COMMENT 'Suchmaschine',
`keywordid` int(11) NOT NULL,
`urlid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2040 ;
在 php 中这个正则表达式有效
preg_match_all ( "#(CREATE.*?);#s", $_POST["sql"], $matches );
在 javascript 中,这个正则表达式返回 null。为什么?
var result = textAreaText.match(/(CREATE.*?);/gm);
【问题讨论】:
-
值是我提供的文本。
-
使用不同的修饰符...期望相同的结果...
s= DOTALL,m= MULTILINE -
也许我使用了不同的修饰符,因为 s 在 javascript 中不起作用,而 javascript 中的 g 与 php 中的 preg_match_all 相同?
-
g很好。那是对的。但是 DOTALL 和 MULTILINE 不一样 ;) -
是的。我只是尝试了所有可用的修饰符,因为 s 不起作用。这就是它存在的原因。:)
标签: javascript php regex