title: Extracting information from Strings
body: <p>When given a string of the form <code>https://website-name.some-domain.some-sub-domain.com/resourceId</code> (type 1) or <code>https://website-name.some-sub-domain.com/resourceId?randomContent</code> (type 2), I need to extract out only two sub-strings. I need the <code>website-name</code> in one string and <code>resourceId</code> in an other string.</p>
  
  <p>I have extracted the website name using the following code:</p>
  
  <pre><code>s := "https://website-name.some-domain.some-sub-domain.com/resourceId?randomContent"
  w := regexp.MustCompile("https://(.*?)\\.")
  website := w.FindStringSubmatch(s)
  fmt.Println(website[1])
  </code></pre>
  
  <p>I have the other regex to get the resourceId</p>
  
  <pre><code>s := "https://website-name.some-domain.some-sub-domain.com/resourceId?randomContent"
  r := regexp.MustCompile("com/(.*?)\\?")
  resource := r.FindStringSubmatch(s)
  fmt.Println(resource[1])
  </code></pre>
  
  <p>This works for any string that ends with <code>?</code> or <code>?randomContent</code>. But I have strings that don't have a trailing <code>?</code> and I am not able to work with such cases (type 1).</p>
  
  <p>I tried <code>"(com/(.*?)\\?)|(com/(.*?).*)"</code> to get <code>resourceId</code> which is of no use.</p>
  
  <p>I am not able to find an elegant way to extract these two sub-strings. </p>
  
  <p>Note: The <code>randomContent</code> is an arbitrarily long substring, the same goes for the <code>resourceId</code> as well. But the <code>resourceId</code> will not have <code>?</code> in it. Upon encountering a <code>?</code>, it can be said that the <code>resourceId</code> has ended.</p>
  
  <p>Also, <code>website-name</code> can differ, but the pattern is the same - An arbitrary sub-domain and a <code>.com</code> will be present in the string.</p>
  
  <p>Here is what I have tried: <a href="https://play.golang.org/p/MGQIT5XRuuh" rel="nofollow noreferrer">https://play.golang.org/p/MGQIT5XRuuh</a></p>