title: Writing a more versatile RegEx for phone number capture
body: <p>I am trying to retrieve phone numbers from the web with Kotlin and JSoup. But i am having some trouble getting the RegEx right. My most effective attempt so far has been:</p>
  
  <pre><code>val pattern = Pattern.compile("\\+[0-9.()-]{7,15}")
  
          val numbers = doc.getElementsMatchingOwnText(pattern)
                          .flatMap {
                              pattern.toRegex()
                                      .find(it.toString())
                                      ?.groups
                                      ?.map {
                                  it!!.value
                              }!!.asIterable()
                          }
  </code></pre>
  
  <p>This is able to get capture numbers that match the +1-###-###-#### format but fails to capture: </p>
  
  <pre><code>+1 (###) ###-#### 
  +1 (###)###-####
  (###)###-####
  </code></pre>
  
  <p>and other north american phone number formats. I have also tried this pattern:</p>
  
  <pre><code>((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
  </code></pre>
  
  <p>and several others from the regex library i found online but they are not working. The site says that it uses the Javascript engine. Possibly this is why they are not working? </p>
  
  <p>I would appreciate any help finding a pattern to capture as many north american phone number formats as possible or finding resources to help me better learn to write my own. Thanks for any help.</p>