ID Preg_match

Thank you for your quick attention to this matter! He is very much appreciated, thanks to everyone who commented, or offered insight!

Hi guys, I have a problem matching my id

I have a line like this in {/describe:foo} , where I try to match {/describe:} to return foo , but I don’t get the regex to the right, someone thought I did wrong? here is 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, for this it’s enough to justify creating replaceable manage words in a string that can be interpreted and replaced, here is an example of a RESTful poster that will run a handle 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; } 
+4
source share
5 answers

There is no slash in your regex:

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

or

 $regexp = '#\{/describe:(.*?)\}#i'; 
+3
source
 $regexp = '/\{\/describe\:(.*?)\}/i'; $query = '{/describe:foo}'; preg_match($regexp, $query, $match); print_r($match); // Array ( [0] => {/describe:foo} [1] => foo ) 
+3
source
 $regexp = '#{/describe:([^}]+)}#i'; $query = '{/describe:foo}'; preg_match($regexp, $query, $match); print_r($match); 
+2
source

In simple terms, you can use this: (?<=\/describe:).*(?=})

+1
source

Try ( / looks like missing before the description):

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

All Articles