I think the problem is your .*. If you look closer, I think you'll find it's finding the first |i, but the last |l. .* tries to match as much text as it can, so it scoops up all your other codes. If you use the non-greedy .*? it should do what you want.