awpti Posted April 22, 2010 Share Posted April 22, 2010 Howdy folks, I've been up and down the regex tutorials and, quite frankly, don't "get" it. I'm trying to do the follow; I have a string as such: perl-HTML-Format.noarch 2.04-6.el5.art atomic I'm trying to figure out how to match the string with regex and take only the perl-HTML-Format and the version portion of the string. The spacing between the package name and version number is not knowable beforehand. I can't exactly explode() on a space as that will give me a huge list of empty array entries with the second element I want placed randomly within that list. I'm thinking a regex would be far more elegant than that. I'm probably over-thinking it. I'd assume a preg_match_all would be the magic in this case, just don't know how to write out the regex. It just doesn't make sense to me. Halp! -G Quote Link to comment Share on other sites More sharing options...
cags Posted April 22, 2010 Share Posted April 22, 2010 No need for preg_match_all as you only wish to match one overall pattern, not multiple instances of the same pattern. Without more details it will be impossible for us to give you an accurate solution. Is the string given below the only content of the string you wish to match the pattern in or is that only a segment. Is any structure constant, i.e. will it always have pert or will it always be something-something-something.something etc. etc. Quote Link to comment Share on other sites More sharing options...
salathe Posted April 22, 2010 Share Posted April 22, 2010 I'm probably over-thinking it. Maybe. Would the following suffice? list($package, $version) = sscanf($string, "%s %s"); Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 27, 2010 Share Posted April 27, 2010 So explode it anyways then: $array=array_filter($array); HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.