I think you should do it in two steps. Step 1: just capture everything that comes after
(which you can do when you apply the first regex), and step 2: look at what you've captured presumably in $4 at the end of the line. Otherwise, the rest of your regex (what you have already) might fail because you are trying to match more things, and these things may or may not be there.