I am learning python, I wanted to capture the data between 'NUMBER:' and \n
NUMBER: 3741733552\n556644
the number after the new line character in variable, hence cannot count on it to capture.
re.search(r'NUMBER:(.*?)[\n]', string_data).group(1)
I tried above code(which is wrong) in vain, please help in capturing that number. Thank you.
Edit:
I have a String "NAME: KHAN NASEEM\n\n22972 LAHSER RD\n\n..." to which I used like the code
name = re.search(r'NAME:\s*(.+)', string_data)
but the output I got is "KHAN NASEEM\n\n22972 LAHSER RD\n\n...", But I want only KHAN NASEEM only.
\n = string literal, not actual new line
r'NUMBER:\s*(\d+)orr'NUMBER:\s*(.+).matches any char but a line break char.\dmatches digits, but mind that in Python 3, it will match any Unicode digits. If you only need to mstch ASCII digits you will have to usere.Aflag or just use[0-9].NAME:\s*(.+)r'\bNAME:\s*(.+?)(?:\\n|$)'is not a good solution because your string is "escaped". Your main problem is the escaped string.