fork download
  1. <?php
  2.  
  3. $str = '[Edit the] Expression & [Text to see matches]. Roll [over matches or the] expression for details. Undo mistakes with ctrl-z. [Save Favorites and Share expressions with friends] or the Community. Explore your results with Tools. [A full Reference and Help is available in the Library or watch the video Tutorial].';
  4. $result = preg_replace_callback('~\[[^][]+]~', function ($m) {
  5. return preg_replace('~\s+~', '$', $m[0]);
  6. }, $str);
  7. echo $result;
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
[Edit$the] Expression & [Text$to$see$matches]. Roll [over$matches$or$the] expression for details. Undo mistakes with ctrl-z. [Save$Favorites$and$Share$expressions$with$friends] or the Community. Explore your results with Tools. [A$full$Reference$and$Help$is$available$in$the$Library$or$watch$the$video$Tutorial].