fork download
  1. <?php
  2.  
  3. $re = "/^(https?:\\/\\/)(s3.amazonaws.com)\\/(\\w+(?:-\\w+){0,2})\\/(.*)/m";
  4. $str = "https://s...content-available-to-author-only...s.com/bucket/folder/d05c229a73b5c6f169d599652015b1.png\n\nhttps://s...content-available-to-author-only...s.com/bucket-with-hyphen/folder/folder1/d05c229a73b5c6f169d599652015b1.png\n\nhttps://s...content-available-to-author-only...s.com/bucket-with-hyphen/folder-with-hyphen/folder1/d05c229a73b5c6f169d599652015b1.png";
  5. $subst = "$1cloudfront.net/$4";
  6. echo preg_replace($re, $subst, $str);
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
https://c...content-available-to-author-only...t.net/folder/d05c229a73b5c6f169d599652015b1.png

https://c...content-available-to-author-only...t.net/folder/folder1/d05c229a73b5c6f169d599652015b1.png

https://c...content-available-to-author-only...t.net/folder-with-hyphen/folder1/d05c229a73b5c6f169d599652015b1.png