Reputation: 2984
I want to match this
{format i=34 ds=11 k=a /}
$patern = "/\{format[a-z0-9=\s]?\/\}/i";
but result is null
In additional question:
string string {format mat=34/} string string string string string string string string
string string {format mat=34/} string string string string string string string string
$pattern = "/{format[a-z0-9=\s]*\/}/i";
str_replace($pattern, 'test', $strings);
it will replace all formats in string, i want to replace only first "format", and remove all another "format". How ?
when get match result is "{format mat=34/}". i want to find string begin with "mat=".
So i have this
$string = "{format mat=34/}";
$pattern = "/^mat=[0-9]*/"; // result is null
$pattern = "/mat=[0-9]*/"; // ok, but also effect with "{format wrongformat=34/}"
How to match string that begin with "mat="
Upvotes: 0
Views: 124
Reputation: 288298
To match something multiple times, use *
. ?
just matches up to one count:
"/\{format[a-z0-9=\s]*\/\}/i"
Upvotes: 3