Stack Exchange
python regex search stop on find \n caracter
i need to scrape data from json string, my current code is :
import re
>>> output = """
... Uploading file 'ex4-to-mq4-ps-decompiler.mp4'...
... Progress:    13.29 Mbps, 3703728 / 3703084 (100.017%) ETA       0s
... Upload successful! Video ID: tZ5xaRLhljc
... Video added to playlist 'decompile mql4' (PL2Q1nwGTMjdeAsBn6mcQ7KuFo6K7_g8_L)
... Video added to playlist 'decompile ex4' (PL2Q1nwGTMjdffMBkc6L4r6SeXnjz7eUiP)
... """
re.search("Video ID: (.+)", output, re.S).group(1)

>>> re.search("Video ID: (.+)?", output, re.S).group(1)
"tZ5xaRLhljc\nVideo added to playlist 'decompile mql4' (PL2Q1nwGTMjdeAsBn6mcQ7KuFo6K7_g8_L)\nVideo added to playlist 'decompile ex4' (PL2

i need extract only id of video tZ5xaRLhljc
how i can do this ?

Your first solution works, remove re.S only. re.search("Video ID: (.+)", output).group(1)

re.S is re.DOTALL which makes . match the newline \n character. If you remove it, . will not longer match newlines and your code will work. Perhaps a more safe solution
re.search(r"Video ID: (\w+)", output).group(1)

where \w matches all "word" characters (i.e. non-whitespace).

Try this:
re.search("Video ID: (.+)\n", output).group(1)

