$re = '/^\[((?!(?:ti|ar|al|au|lr|length|by|offset|re|tool|ve|#|\d{1,2}):.+\]).*)\](\r?\n)(\[\d{1,2}:\d{1,2}\.\d{2,3}\])(.*)$/m';
$str = '[ti:Hey You]
[ar:Pink Floyd]
[al:The Wall (2011 Remaster)]
[au:Roger Waters]
[lr:Roger Waters]
[length:04:40]
[by: Casual Tea]
[offset:+300]
[re: Musicbee]
[tool: Mp3tag]
[ve: 1.2.3]
[#: A comment]
[Acoustic Guitar Intro]
[Verse 1: David Gilmour]
[00:35.485]Hey you
[00:38.184]Out there in the cold,
[00:39.828]Getting lonely, getting old,
[00:41.848]Can you feel me?
[00:46.137]Hey you
[00:48.659]Standing in the aisles
[00:50.250]With itchy feet and fading smiles,
[00:52.611]Can you feel me?
[00:57.924]Hey, you, don\'t help them to bury the light
[01:08.393]Don\'t give in without a fight
[01:13.227]
[Verse 2: David Gilmour]
[01:20.282]Hey, you
[01:23.035]Out there on your own,
[01:24.566]Sitting naked by the phone,
[01:26.685]Would you touch me?
[01:30.958]Hey, you
[01:33.071]With your ear against the wall,
[01:35.171]Waiting for someone to call out,
[01:37.348]Would you touch me?
[01:42.711]Hey you, would you help me to carry the stone?
[01:52.884]Open your heart, I\'m coming home
[01:58.076]
[Guitar Solo]
[Bridge: Roger Waters]
[02:57.282]But it was only fantasy
[03:04.137]The wall was too high, as you can see
[03:11.617]No matter how he tried, he could not break free
[03:19.019]And the worms ate into his brain
[03:22.914]
[Verse 3: Roger Waters]
[03:54.974]Hey, you
[03:57.745]Out there on the road,
[03:59.261]Always doing what you\'re told,
[04:01.459]Can you help me?
[04:05.745]Hey, you
[04:08.135]Out there beyond the wall,
[04:09.899]Breaking bottles in the hall,
[04:12.108]Can you help me?
[04:17.481]Hey, you, don\'t tell me there\'s no hope at all
[04:27.360]Together we stand, divided we fall
[Outro: Roger Waters]
[04:32.742](We fall)
[04:34.133](We fall)
[04:35.313](We fall)
[04:36.593](We fall)
[04:37.885](We fall)
[04:39.178](We fall)
[04:40.433]';
$subst = "$3($1)$2$3$4";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php