... \s*([^,]+)\s*,... Find some whitespace, or perhaps none at all. Find anything that is not a comma, at least once, which *includes* whitespace, then... Find some more whitespace, perhaps none Find a comma #### m#(?:[^,]*,\s*){3}(.*?)\s*,# #### (?: ## Group, but do not store it into $1 [^,]* ## Anything that is not a comma , ## Followed by a comma \s* ## Followed by possible whitespace ){3} ## Find three of these (the first three) (.*?) ## Match any character, but don't be so greedy about it \s* ## Possible whitespace , ## Stops at first comma, because we are not being greedy