Chameron
Chameron

Reputation: 2984

php - regexp match string and digit

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 
  1. $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 ?

  2. 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

Answers (1)

phihag
phihag

Reputation: 288298

To match something multiple times, use *. ? just matches up to one count:

"/\{format[a-z0-9=\s]*\/\}/i"

Upvotes: 3

Related Questions