-1

Let's say you have this variable,

String message = "This is a link http://www.example.com/"

or you have this,

String message2 = "This is a link http://www.example.com/ and another link http://www.myfico.com/Images/sample_overlay.gif"

How can I extract only the link into a list?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Andy
  • 9
  • 2

1 Answers1

1

Something like this will work for the two examples you give:

def links = message2.findAll(/http:\/\/\S+/)

That is, find anything that starts with http:// up until some sort of whitespace

There are more complex regular expressions over on this question, but I've not tried any of them, and they may be overkill for your situation

Community
  • 1
  • 1
tim_yates
  • 167,322
  • 27
  • 342
  • 338