Andrew
Andrew

Reputation: 7788

Best way to get links from strings that contain them

I have a list of links, but I need to FILTER-OUT and EXTRACT correct links from the String.

Extract should start with mywebsite.com and which end with 9-digitnumber.html Links are strings, extracted to string

Example

http://blah.com?f=www.mywebsite.com/sdfsf/sdfsdf/sdfsdfsdf/123456789.html&sdfsdf/sf/sdfsd8sdfsdfsdf

and so on...

From this, regex must extract

mywebsite.com/sdfsf/sdfsdf/sdfsdfsdf/123456789.html

This should match the number in the end '@"[0-9]{9}". but I am very new to regex and trying to learn how to use it properly

Upvotes: 0

Views: 98

Answers (2)

Tyilo
Tyilo

Reputation: 30112

/mywebsite\.com\/[a-zA-Z0-9\/]*[0-9]{9}\.html/

Upvotes: 1

David Brabant
David Brabant

Reputation: 43539

Parsing HTML with regexs is usually a bad idea. For you particular example, you can use:

(mywebsite.com/(.+?)\d{9})

but as Andrew said, using a regex for doing what you want is not really necessary.

Upvotes: 1

Related Questions