You have to escape your []
as follows:
preg_match('/^\[image(.*)\]$/',$text);
Also, as @h2ooooooo said, this will have better performance:
^\[image[^\]]+\]$
It works now. You can see it here --v
Frage
I try to use preg_match to find the phrase: "[image: Inline images num]" in the text Unfortunately I could not,
this is my try:
preg_match('/^[image(.*)]$/',$text);
thank you for your help!
Lösung
You have to escape your []
as follows:
preg_match('/^\[image(.*)\]$/',$text);
Also, as @h2ooooooo said, this will have better performance:
^\[image[^\]]+\]$
It works now. You can see it here --v
Andere Tipps
if (preg_match('/\[image:.*?\]/i', $subject)) {
# Successful match
} else {
# Match attempt failed
}
Match the character “[” literally «\[»
Match the characters “image:” literally «image:»
Match any single character that is not a line break character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “]” literally «\]»