I cannot figure out how to accomplish this in PHP (Running 5.3.x).
I have the following string of text which I’m pulling from a txt file into a string variable:
garbage here, more garbage here, more garbage, mor ..., garbage here, more garbage here, more garbage, mor ..., more garbage here, yet more garbage
What I’m trying to get the string to look like and put back into the txt file is:
garbage here, more garbage here, more garbage, garbage here, more garbage here, more garbage, more garbage here, yet more garbage
I’m trying to figure out a way to find each occurrence of the “…” and then remove all text behind “…” until it hits the first occurrence of “,” but without any luck. Can this be done using a regex with the preg_replace function? So far, I’ve only managed to delete all the text between the first occurrence of “,” and “…” but this is not what I want. 🙁
There will be no additional commas or “…” inside the “garbage here” strings…
Also “…” does not always have a trailing “,”. It could just be “mor… more garbage here”
I only have PHP available for this task. Can it be done? I picked up a regex book this afternoon but so far I haven’t found anything that will do exactly what I’m trying to accomplish.
Any help would be greatly appreciated.
You should be able to use the following regex:
Replace matches with an empty string.
Explanation: