-2

Dears,

I've tried "\b \b" and (.*)["] to get the regex which lets me select the url starting with "my.website" and ends with "myfile" for this URL in source code:

<a class="URL" href="http://my.website.com/a/b/cdefghijklmnopqrstuvwxyz/myfile" target="_blank">

any ideas please!

Shafizadeh
  • 9,960
  • 12
  • 52
  • 89
M. A.
  • 424
  • 6
  • 21
  • Please post the regex that you've tried, what it's matching, and explain where you think it might be going wrong. – clinton3141 Apr 18 '16 at 20:32

2 Answers2

1

Use this pattern:

"(.*my.website.*myfile)"

Online Demo

Then $1 containing expected URL.

  • " matches the characters " literally
  • ( capturing group
  • .*my.website anything til my.website
  • .*myfile anything til myfile
Shafizadeh
  • 9,960
  • 12
  • 52
  • 89
1

this will be a generic solution

$ grep -oP "(?<=href=\"http://)[^\"]+" file

my.website.com/a/b/cdefghijklmnopqrstuvwxyz/myfile
karakfa
  • 66,216
  • 7
  • 41
  • 56