At first, there was a suggestion of using "==" instead "~" in the regex,
The comparator to use should be "==" (please see https://gist.github.com/dimsemenov/10100415#file-vcl-regex-cheat-sheet-L10)
But there were some other considerations that invalidated the first suggestion
Simply changing it from "~" to "==" might not be the way to go. Yes, it would fix the issue of a match for "123" also matching "1234", but it would also prevent it from matching "87,123", when you have multiple X-Location-IDs on a single document, and need the document purged because of it.
My initial thought is that you'd want to keep using the "~" operator, but improve the regexp, so you more accurately target what needs to be purged.
Something along the lines of this:
The idea being to match the X-Location-Id, but only if it's either at the start of the value, or there's a comma in front of it, and also only if it's either at the end of the value, or there's a comma behind it. That way, you'd both match "87,123" (comma in front, end of value behind), and also not match "1234" (start of value in front, but neither comma nor end of value behind).
There are multiple regexp dialects, so please take the exact regexp I suggested with a grain of salt, this should probably be tested properly before updating the default vcl.
This seems like a better regexp to use: (^|,)req.http.X-Location-Id(,|$)