Trying to figure out a reg ex, for example, this string:
*/30 * * * * http://www.domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
I need to capture the beginning */30 * * * *
and ending value of /wp-cron.php?doing_wp_cron >/dev/null 2>&1
, but it doesn't matter what is in between those values.
Also, the beginning part of: */30 * * * *
, can also sometimes be these values:
0 * * * *
or
0 0 * * *
In which case, I'll need a regex for this as well, or, if one can do them all, that would be great!! The beginning part is actually within a string variable if that matters. Which can be any of the following values above.
How can I do this?
So far, I have something like this: ^\*\/30 [\*].+\s[*4]
But my regex skills are slim to none and this only matches the beginning... need to match the end, of if there is a way to put the site_url()
into the regex also, and we can match the entire line, which would be preferred.
EDIT
Ok, so there is a variable like this: site_url()
, this will return a WordPress Blog site URL in a string, like this: http://www.domain.com
.
Now, there is another variable called, $updateinterval
, this will contain any of the string values: */30 * * * *
, or 0 * * * *
, or 0 0 * * *
Now, I build a string from these variables like so:
$cron_job = $updateinterval . ' ' . site_url() . '/wp-cron.php?doing_wp_cron >/dev/null 2>&1';
It than uses this to insert a Cron Job in PHP (supposedly). However, in order to remove the cron job (thus cleaning up if there is no need for it anymore), I need to use a regex to find the line for the cron job, and edit the file needed to remove it.
Now, I can get the FULL string of what is set within $cron_job at anytime, even what was set previously. So, in that case, if it is possible to match the entire string $cron_job
with a regex, that is what would be best. But, how to use these variables $updateinterval
and site_url()
within a regex?
So, I have a class that uses preg_grep
to remove the line where the cron job is being set. But how to use it to match all of the possible values from the variables? Or just grab the start and end constants? Whichever way is fine with me.
* RE-EDIT* So, for example, it needs to search within a file, and if any of these are found (REGEX), than it is a match and will be removed by the cron job:
// let's just say that site_url() resolves to: http://www.domain.com for the sake of this. This will be different on a per site basis ofcourse.
*/30 * * * * http://www.domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
0 * * * * http://www.domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
0 0 * * * http://www.domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Anything else should FAIL, anything at all besides the 3 strings above should fail! So the regex should only match the 3 given strings above and that's it. That is to say, whatever site_url()
is, it should add it to the regex, if possible.