开发者

Including carriage returns in PHP regex

How do I rewrite the following regex expression to include carriage returns and spaces?

mysql_query\("(.*)"\)

It should match the following types of data.

String with carriage returns:

$result = my_mysql_query("
SELECT foo, bar
FROM mytable
ORDER BY name");

String with some carriage returns:

$result = my_mysql_query("SELECT foo, bar
FROM mytable
ORDER BY name");

String with no carriage returns:

$result = my_mysql_query("SELECT foo, bar FROM mytable ORDER BY name");开发者_JAVA技巧


If you use PCRE (used by PHP's preg_*() functions), use the s modifier so . matches carriage returns and newlines:

/mysql_query\("(.*)"\)/s


Answering my own question... The better regex is:

/mysql_query\("(.?)"\)/s
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜