So, I basically want to match a pattern where I have one or more space separated values. I’d like to use either preg_match or preg_match_all to get each value, separated.
I can easily get them all together (which I could then split), but is there a way to do it with one call that I’m just missing?
I’d like to somehow make it so $matches would contain “a”, “b”, “c”, “d” all separately. I can do it with two matches (making the second just match spaces), but I can’t get it to do it in one.
split() (the opposite of join()) is what you’re looking for. Without removing "something " from the $str, the assignment array will have split[1] = “something” before you get to your meaningful values.
My example was overly simplistic, I’d have to do some regex to get that list of space separated values. I can easily split them afterwards (multiple whitespace characters between the values are valid, so I need to use regex to split them as well, since a simple split on " " won’t work).
I was just hoping I could combine those two regex into one some how. =p