Reputation: 183
I need a regular expression to find all the lines that begins with /*
$num_queries = preg_match_all(
'REG_EXP',
file_get_contents(__DIR__ . DIR_PLANTILLAS . '/' . 'temp_template.sql')
);
I try this '^\/\*.*'
but it does not work.
Upvotes: 1
Views: 211
Reputation: 23017
If you use this string: /^\/\*.*/
in the preg_match()
function, it'll work. This pattern matches /*
followed by maybe some text.
Make sure the regular expression will be performed on each line. I recommend that you first split the string (file contents) by a newline. You can use the function preg_split()
in order to do so.
If you don't want to split the file contents by each line first, then you can use the following pattern: /(^|\n)\/\*(.*)/
. That pattern matches first either the beginning of the string or a newline, followed by /*
, followed by maybe some text.
Notice that in the patterns /^\/\*.*/
and /(^|\n)\/\*(.*)/
the /
is used as delimiter. That means that further occurences of /
must be escaped.
Upvotes: 1
Reputation: 474
Please, note, what you deal with multiline content, but ^ means beginning of content, not a beginning of a line.
try (\/[^\r\n]+)[\r\n$]+
Upvotes: 0