title: How get range from regex matches
body: <p>I'm looking for a way to get the ranges from a regex match. I have a string </p>
  
  <blockquote>
    <p>I'm looking for @{1 | Tom Lofe} and @{2 | Cristal Dawn}</p>
  </blockquote>
  
  <p>From this string, I need to get the ranges of these matches using the following regex </p>
  
  <pre><code>"@\\{(\\d+) ?\\| ?(\\w+ *?\\w*?)\\}"
  </code></pre>
  
  <p>What is the best way to do this? So far I've only been able to get the matches but not the ranges. Apparently, the standard Swift function <code>range(of: &lt;#T##StringProtocol#&gt;, options: &lt;#T##String.CompareOptions#&gt;, range: &lt;#T##Range&lt;String.Index&gt;?#&gt;, locale: &lt;#T##Locale?#&gt;)</code> should be able to do this, but I don't know how to use it, and can't seem to find a good example.</p>
  
  <p>I've also tried this question's answer <a href="https://stackoverflow.com/questions/36865443/get-all-ranges-of-a-substring-in-a-string-in-swift">get all ranges of a substring in a string in swift</a> but again am unable to get it to work. </p>