0

I will be receiving list of url daily. And in those urls two letters country code will be present like uk, no, fr, de

Sample urls are like below

www.abc.com.uk/services
www.prices.com/de-de  (in this case first de is language and second is country)
www.customers.com/fr-fr/services

So that two letter country code always change its position. How can I get that two letter country code from these types of random urls using java without hardcoding all country codes and check one by one ?

Any Ideas please...!

linuxman
  • 51
  • 8
  • 2
    Random? Not possible. You'll need to parse these according to the possibilities and live with that. The first one suggests that you want to get it from the .uk that follows .com. The dash regex solution can't work for that. – duffymo Jan 05 '18 at 15:43
  • You can write code to handle a lot of top-level domains like `.es` and `.fr`, but for links where the country code is near the end of the URL (like `www.customers.com/fr-fr/services`) you will need to be creative and apply [heuristics](https://en.wikipedia.org/wiki/Heuristic). – byxor Jan 05 '18 at 15:47
  • Calling this an exact duplicate of string-splitting seems like a bit of a stretch to me. The question isn't asking "how do I split strings?", it's asking something broader ("how can I reliably get the country code from URLs even when they aren't part of the top level domain"). Splitting strings is only part of a possible implementation, thus I don't consider it a duplicate. – byxor Jan 05 '18 at 15:56

0 Answers0