# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(#EXTM3U\s+|#EXTINF:\d+,|(.*\.\w{3,4}).*\s+)"
test_str = ("#EXTM3U\n"
"#EXTINF:419,Alice in Chains - Rotten Apple\n"
"http://192.168.101.22:80/movies/9975.mkv\n"
"#EXTINF:260,Alice in Chains - Nutshell\n"
"http://192.168.101.22:80/movies/1254.mkv\n"
"#EXTINF:255,Alice in Chains - I Stay Away\n"
"http://192.168.101.22:80/movies/1254.mkv\n"
"#EXTINF:256,Alice in Chains - No Excuses\n"
"Alice in Chains_Jar of Flies_04_No Excuses.mp3\n"
"#EXTINF:157,Alice in Chains - Whale And Wasp\n"
"Alice in Chains_Jar of Flies_05_Whale And Wasp.mp3\n"
"#EXTINF:263,Alice in Chains - Don't Follow\n"
"Alice in Chains_Jar of Flies_06_Don't Follow.mp3\n"
"#EXTINF:245,Alice in Chains - Swing On This\n"
"Alice in Chains_Jar of Flies_07_Swing On This.mp3\n")
subst = ""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html