I need to check a string for a certain string, I want to use regex for this, but the more I keep trying, the more it confuses (and frustrates) me; I can't seem to get it right.
I need the expression to return true when the string contains something like this: [[module:instance]]
, but it needs to meet the following conditions:
[[
:
, and has no limit to it's length:
character must be present:
again a string that can contain everything except a :
, and has no limit to it's length]]
Any help, tips, good tutorials, anything would be greatly appreciated!
Thanks in advance!
Try this:
preg_match('/\[\[[^:]+?:[^:]+?]]/', $str, $match)
An explanation:
\[\[
matches the literal [[
[^:]+?
matches anything but :
(non-greedy):
matches the literal :
[^:]+?
matches anything but :
(non-greedy)]]
matches the literal ]]
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With