php - Escaping my own regular expressions -


i have function replaces matched content other content larger body of text.

this [5] content

so in example, regex looks in '[]' , replaces content determined '5', lets string table index of 5.

here regex using:

/(?<!/)\[(.*?)\]?\]/ 

theres few bracket checks other functionality, , there behind right excluding tag preceded '/'

what want do, when tag escaped / remove escape character , move on the next match.

so:

this /[5] content

becomes:

this [5] content

as opposed to:

this [5] content

becoming:

this [insert content here] content

i hope that's not confusing.

the way i'm replacing matched content recursive function finds first match, replaces it, updates original material, , calls it's self until there no matches left. source of problem, not figure out way of doing it. if preg_match matches once , loop through each, updating original content, position of matched tags changes when preg_match run , gets mixed up.

heres paste of function in question http://pastebin.com/ckvxnaxt

so discovered preg_replace_callback seems suit needs well

return preg_replace_callback( $tagregex, function($matches){   //if match starts '/' remove slash , return   //otherwise logic } ,$content); 

my finished product http://pastebin.com/qj1g0ppq


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -