title: Extracting numbers from a text file using regexp
body: <p>Iam trying to make a python script that reads a text file input.txt and then scans all phone numbers in that file and writes back all matching phone no's to output.txt</p>
  
  <p>lets say text file is like: </p>
  
  <blockquote>
    <p>Hey my number is 1234567890 and another number is +91-1234567890. but if none of these is available you can call me on +91 5645454545 (or) mail me at abc@xyz.com</p>
  </blockquote>
  
  <p>it should match <strong>1234567890</strong>, <strong>+91-1234567890</strong> and <strong>+91 5645454545</strong></p>
  
  <pre><code>import re
  
  no = '^(\+[1-9]\d{0,2}[- ]?)?[1-9][0-9]{9}' #i think problem is here
  f2 = open('output.txt','w+')
  
  for line in open('input.txt'):
      out = re.findall(no,line)
      for i in out : 
          f2.write(i + '\n')
  </code></pre>
  
  <p>Regexp for no is like : it takes country codes upto 3 digits and then a - or space which is optional and country code itself is optional and then a 10 digit number.</p>