regex knowledge aside, a quick look at your code and your problem, leads me to suspect that you want 1- in the second $gettok rather than 2-