Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preg_match identifier

I want ot get a match from my identifier.

I have a string like this coming in {/describe:foo} where I am trying to match {/describe:} to return foo, but am not getting the regex right, would someone mind pointing out what I did wrong? here's my match.

$regexp = '/\{describe:(.*?)\}/i';
$query  = '{/describe:foo}'; 
preg_match($regexp, $query, $match);

print_r($match); // (bool) false

Background I hope this can help others, a good reason to do this is to create replaceable control words in a string that can be interpreted and replaced, here's an example of a RESTful poster that will run a descriptor on a control word.

  if (preg_match('/\{describe:(.*?)\}/i', $_POST['query'], $match))
  {
        // Describe Salesforce Object from internal POST tool
        print_r($SforceConnection->describeSObjects($match[1]));
        exit;
  }
like image 995
ehime Avatar asked Dec 27 '22 07:12

ehime


1 Answers

You are missing the forward slash in your regexp:

$regexp = '/\{\/describe:(.*?)\}/i';

or:

$regexp = '#\{/describe:(.*?)\}#i';
like image 110
jeroen Avatar answered Jan 10 '23 23:01

jeroen