php - Replace the wrapper (parent) string by regular expression and preserve the inner child content -


i have multiple files have obsolete format , replace them latest format. 1 of trouble finding wrapper string , replace them while have preserve inner content.

example

i want convert expression abc($ignore$) xbd([$ignore$])->t. here string format of needs updating.

input:

... abc( ...... ..... (inner content should not changed) ..... ......) .... 

output:

... xbd([ ...... ..... (inner content should not changed) ..... ......])->t .... 

how achieve it?

you can use following regex able match nested round brackets:

\babc(\(((?>[^()]+)|(?-2))*\)) 

replace xbd$1->t.

see demo

sample php code:

<?php     $re = "#\babc(\(((?>[^()]+)|(?-2))*\))#";      $str = "abc( ......\n..... (inner content should not changed) .....\n......) ";      $subst = "xbd$1->t";      echo $result = preg_replace($re, $subst, $str); ?> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -