Skip to content

Instantly share code, notes, and snippets.

@rd13
Created April 5, 2013 17:05
Show Gist options
  • Save rd13/5320930 to your computer and use it in GitHub Desktop.
Save rd13/5320930 to your computer and use it in GitHub Desktop.
Regex to match square brackets at end of string
$v = "Muse - Supermassive Black Hole[Dubstep Version][muse.mp3]";
//Match ending [], that contains .mp3
preg_match("/\[([^]]*.mp3+)\]$/i", $v, $match);
//Remove [] from matched string
$track_url = preg_replace('/[[\]]/', '', $match[0]);
//Remove mp3 link from title
$track_title = preg_replace("/\[([^]]*.mp3+)\]$/i", '', $v);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment