0

Currently on regex101 and I'm using the below test string:

Sinkhole: Unknown, URLReputation: Risk unknown, URL: https://35.com/tail/123@#$%^, URLCategory: Unknown

What I'm trying to achieve using regex is to get a full match like below:

URL: https://35.com/tail/123@#$%^

The regex I'm using is detailed below:

URL:\s((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$

Unfortunately, the regex above is capturing anything after the URL which is not what I need.

I'm new to regex and understand the basics but missing that last piece.

Nina G
  • 269
  • 5
  • 17
  • what do you want to obtain exactly? – Ass3mbler Jan 23 '19 at 19:15
  • 1
    It seems like you're doing some validation as well, which we would require more details on to help you. A simple `URL: ([^,]*),` would capture anything following `URL: ` to the next `,`, [e.g. here](https://regex101.com/r/syWRh3/1/) thought it seems your needs are more complex than this. – zzevannn Jan 23 '19 at 19:17
  • Use `URL:\s*(.*?),\s` and get Group 1 value. See [this regex demo](https://regex101.com/r/L49jjc/1) – Wiktor Stribiżew Jan 23 '19 at 19:20
  • @Ass3mbler I'm trying to return the URL: and the actual url. As an example, URL: https://someurl.com/whateverelsehere. – Nina G Jan 23 '19 at 20:28
  • @zzevannn what you suggested is exactly what I need. The original regex I had was something I found just googling but what you stated is all I need. Thanks. – Nina G Jan 23 '19 at 20:29
  • @WiktorStribiżew Thanks! – Nina G Jan 23 '19 at 20:30

0 Answers0