# https://stackoverflow.com/questions/67489442/python-regex-how-to-restrict-a-given-regex-pattern-to-a-range-of-character

import re
text = '''

547 U18101MH1988PTCO50073 =RAINBOW GARMENTS AND EXPORTS (INDIA) PRI
548 UU24230MH2004PTC147574 RAINBOW HERBAL AND RESEARCH PRIVATE LIMI
549 U55200MH1992PTCO067327 RAINBOW HOLIDAY-INNPVT.LTD.

550 U15100MH2004PTC148619 RAINBOW HORTICULTURE PRIVATE LIMITED

551 US9S99S9MH2000PTC124660 RAINBOW INFOTECH (INDIA) PRIVATE LIMITED
552 U70200MH2011PTC221779 RAINBOW INFRAVENTURES PRIVATE LIMITED
553 U15130MH2004P1C14/013 RAINBOW JELSTAR FOODS PRIVATE LIMITED
'''

x = re.findall('U.*\d{5}.*\d{1,21}', text)

print(x)