title: Regex : extract the biggest number from x to y figures
body: <p>I have an Url formatted as follow : <a href="https://www.mywebsite.com/subdomain/123456789.htm" rel="nofollow noreferrer">https://www.mywebsite.com/subdomain/123456789.htm</a>. I know that the webpage number is built with exactly 9 or 10 digits. I would like to extract this number using a Regex. </p>
  
  <p>The Regex I use to perform this operation is : </p>
  
  <p><em>^https://www.mywebsite.com/[A-Za-z0-9_.-~/]+([0-9]{9,10}).htm$</em> </p>
  
  <p>The problem is that when the number is 10 digits long, I get a match which is good but only the last 9 digits are captured. For example :  <a href="https://www.mywebsite.com/subdomain/1234567890.htm" rel="nofollow noreferrer">https://www.mywebsite.com/subdomain/1234567890.htm</a> captures 234567890 only.  </p>
  
  <p>I could easily create two regexes (one with 9 digits and one with 10) and take the longest number if both matches, but is there any elegant way to solve this problem using Regex? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Following remarks which have been made below,  there is actually a mistake in my original Regex : the first character group matches the first digit of the 10, and leaves only the 9 others for the capturing group. I've added a screenshot below.  Adding a forward slash to the Regex before the capturing group solved the issue, thanks!</p>
  
  <p><a href="https://i.stack.imgur.com/LpMdE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LpMdE.png" alt="Wrongly formatted Regex"></a></p>