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
精彩评论