Forum Academy Marketplace Showcase Pricing Features

Question about RegEx and extracting from URLs

Hey everyone,

For my app I’d like to extract parts of an URL. Users either put in,,, or (or whatever variation they come up with…) and I’d always like to be able to take the ‘Tesla’ part. It’s what I’ll use in my database as the company name.

Is there anyone that can help me sort out the RegEx part? I’ve been on regex101 for hours now and I’m getting a headache :slight_smile:

Update: this works more or less, however not 100% of the time -> (?<_name>(\d{1,3}.\d{1,3}?|[^.\s]+?).([^.\s]{1,3}|[^.\s]{1,3}.[^.\s]{1,3}))$

This might be helpful -