Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I have a list like

list = {"my element 1 http://link.com", "http://link2.com my element 2"}

how do I get a list of the links inside each element?

Something like

StringCases[list, "http" ~~ _]

probably but I wasn't able to know how to end my pattern.

share|improve this question
    
Yet another way, Select[StringSplit[#], StringMatchQ[#, "http://*"] &] & /@ list. Sorry about the nested Function. –  Szabolcs Oct 22 '13 at 15:01
    
@Szabolcs go answer! –  Yves Klett Oct 22 '13 at 17:21
add comment

2 Answers

up vote 9 down vote accepted

One way:

StringCases[list, "http://" ~~ Except[WhitespaceCharacter] ..]

{{"http://link.com"}, {"http://link2.com"}}

share|improve this answer
    
that's great but I don't see what the pattern ".." does in the documentation? –  su1 Oct 21 '13 at 12:22
1  
@su1 Look up Repeated, a good friend on many a jolly pattern matching occasion :-) –  Yves Klett Oct 21 '13 at 12:24
add comment

Another way, similar to @YvesKlett, but with RegularExpression.

StringCases[list, RegularExpression["http://\\S+"]]

{{"http://link.com"}, {"http://link2.com"}}

In RegularsExpression \\S means non space characters. You can find more information in Wolfram documentations here

share|improve this answer
1  
You could give a short description of your regex to make it even more educational ;-) –  Yves Klett Oct 22 '13 at 14:06
    
@YvesKlett Agree. Done! –  Murta Oct 22 '13 at 20:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.