Jump to content

Finding two pieces of data in a string ...


awpti

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.