title: Python Regex - STRING with [A-Z] and DIGITS [\d]
body: <pre><code>import re 
  
   str_1 = "ABABABABABAabababaacdcdcdcd"
   str_2 = "ABABABABAB1ab2babaacdcdcdcd"
   str_3 = "123456A"
   str_4 = "123456"
  
   #str_3Plus_d = re.search(r'(?=.*?\d)[A-Z\d]{10,}',str_2).group(0)
   str_3Plus_d = re.search(r'(?=.*?\d)[A-Z\d]{2,4}',str_2).group(0)
   print(str_3Plus_d)
  
   #str_3plus_a = re.search(r'(?=.*?\d)(?=.*?[A-Z])[A-Z\d]{3,}',str_4).group(0)
  
   #str_3plus_both = re.search(r'(?=.*?\d)(?=.*?[A-Z])[A-Z\d]{3,}',str_4).group(0)
  </code></pre>
  
  <p>I am stuck with searching a STRING ([A-Z] and DIGITS). I searched SO for similar Questions ,  here -- <a href="https://stackoverflow.com/a/28334645/4928635">https://stackoverflow.com/a/28334645/4928635</a>, it says that <strong>(?=.*?\d)</strong> "Checks for atleast one digit" , but that doesnt seem to be the case. As seen in - </p>
  
  <pre><code>str_3Plus_d = re.search(r'(?=.*?\d)[A-Z\d]{2,4}',str_2).group(0)
  print(str_3Plus_d)
  </code></pre>
  
  <p>it prints me a string - which has no digits ? String it print in my JupyterNotebook is as seen below - </p>
  
  <pre><code> ABAB
  </code></pre>
  
  <p>How to capture a string with - "variable number of characters and at least 2 digits and at most 4 digits , as an example - how to catch - AAABBB2223" ...</p>
  
  <p>Further clarifications -- </p>
  
  <ol>
  <li><p>@pm-2ring :- the digits and alpha characters can occur in any order , the substring im trying to capture can vary in length. </p></li>
  <li><p>@jean-françois-fabre :- you seem to have removed your answer - the code you gave did exactly what u said it would - thanks .</p></li>
  <li><p>@clasg :- Both your comment and answer have taught me well today - im very grateful - i will revert in sometime and let you know if i would want to upvote your answer - many thanks. </p></li>
  </ol>