-1

I wrote this regex :

http://regexr.com/3cbis

Its job is to capture a web address but remove the filepath. e.g. www.example.com/removethis/andthis/ - leaving me with just www.example.com

The .NET tester I used (regexstorm.net/tester) gave me a different output.

How would I fix my regex to give my desired result?

Sam B
  • 41
  • 1
  • 1
  • 4

2 Answers2

2

Don't use a regex, use the Uri class which has built in Host property to extract the relevant part of the url.

Andrew Hanlon
  • 7,271
  • 4
  • 33
  • 53
-1

Use the URI class

See this stack overflow for an example

How can I parse HTTP urls in C#?

Community
  • 1
  • 1
PingCrosby
  • 369
  • 4
  • 17