0

I am trying to recognize and parse the following string:

HTTPS Access https://ftp.abc.def.com/dir1<about:blank%20https:/ftp.abc.def.com/dir1>

What I want to pull out is

host = ftp.abc.def.com

I use the following regular expression:

(?i)https:\/\/<?host>\S+)\/(?<dir>\S+)

which gives me

host = ftp.abc.def.com/dir1<about:blank%20https:/ftp.abc.def.com

Why is the host being matched all the way to the last / and not just the first?

JeffR
  • 828
  • 1
  • 13
  • 22
  • 5
    [Greediness](http://stackoverflow.com/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers#5319978). – Robin Jun 04 '14 at 08:35
  • 1
    add `?` to `\S+`, so it would be `\S+?` – j3ny4 Jun 04 '14 at 08:36
  • 1
    I would use the right tool for the job: `string host = new Uri(input.Substring(input.IndexOf("https://")), UriKind.Absolute).Host`. The result is: `"ftp.abc.def.com"` – Tim Schmelter Jun 04 '14 at 08:47

0 Answers0