0

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="

3
  • Because you forgot about a quantifier for your character set. Just replace ? with * Commented Apr 16, 2011 at 16:05
  • in pattern i have "\s", it not match space ? Commented Apr 16, 2011 at 16:06
  • it does ;-) I deleted my that comment after few seconds after I posted it ;-) Commented Apr 16, 2011 at 16:08

1 Answer 1

3

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

"/\{format[a-z0-9=\s]*\/\}/i"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.