PHP Regex to extract parameters within double square brackets (Modx Tags) -


i'm trying write regex extract value of particular parameter array of content in modx database. format of tags is:

[[!video? &path=`_path_to_video` &width=`123` &height=`123` &someotherparm=`bar`]]  

i trying content of &path parameter using regex:

preg_match_all('/\[\[path=`(.*?)`\]\]/', $content, $tags, preg_pattern_order) ; 

but without luck - returns empty arrays when dump $tags variable.

something wrong regex?

your pattern doesn't match tag format:

preg_match_all('/&path=`([^`]+)`/', $content, $tags, preg_pattern_order); 
  • match &path= backtick, then
  • match not backtick until backtick , capture it

if need match existence of [[ , closing ]] then:

preg_match_all('/\[\[.*&path=`([^`]+)`.*\]\]/', $content, $tags, preg_pattern_order); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -