Is it possible to get all regular expression matches in PHP? I need a script that will, for example, match .+ in abc and give the result:
Array(a, b, c, ab, bc, abc)
Is it possible to get all regular expression matches in PHP? I need a script that will, for example, match .+ in abc and give the result:
Array(a, b, c, ab, bc, abc)
I'm not sure there is a defined set of "all matches" in a regular expression.
For example, what if your pattern were .+.+? What is matched by the first .+? What is matched by the second?
A string may match a particular RE binding in multiple different ways, and which substring is captured by different parts of the RE may depend on things like greedy vs. non-greedy matching. But there is no defined way to iterate over all the different possible captures. You'd have to dramatically change the way that REs are processed to do this.