开发者

Including carriage returns in PHP regex

开发者 https://www.devze.com 2023-02-05 04:26 出处:网络
How do I rewrite the following regex expression to include carriage returns and spaces? mysql_query\\(\"(.*)\"\\)

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

精彩评论

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