fork download
  1. <?php
  2.  
  3. $str = "/hello/{:num}/{:str}/";
  4. $replace = [
  5. "num" => "[0-9]",
  6. "str" => "[a-zA-Z]"
  7. ];
  8. '/{:(.*)}/U',
  9. function ($matches) use ($replace) {
  10. if(isset($replace[$matches[1]])) {
  11. return $replace[$matches[1]];
  12. }
  13. else {
  14. return $matches[0];
  15. }
  16. },
  17. $str
  18. );
  19. echo $str;
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
/hello/[0-9]/[a-zA-Z]/