# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\w+)\s+:\s(.+)$"
test_str = ("ffprobe C:/Users/spike/Music/Sample.flac\n"
"ffprobe version N-89971-g8318bf1751 Copyright (c) 2007-2018 the FFmpeg developers\n"
" built with gcc 7.2.0 (GCC)\n"
" configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth\n"
" libavutil 56. 7.100 / 56. 7.100\n"
" libavcodec 58. 10.100 / 58. 10.100\n"
" libavformat 58. 9.100 / 58. 9.100\n"
" libavdevice 58. 1.100 / 58. 1.100\n"
" libavfilter 7. 11.101 / 7. 11.101\n"
" libswscale 5. 0.101 / 5. 0.101\n"
" libswresample 3. 0.101 / 3. 0.101\n"
" libpostproc 55. 0.100 / 55. 0.100\n"
"Input #0, flac, from 'C:/Users/spike/Music/Sample.flac':\n"
" Metadata:\n"
" TITLE : Believer (Kaskade Remix)\n"
" ALBUM : Believer (Kaskade Remix)\n"
" PERFORMER : Imagine Dragons\n"
" album_artist : Imagine Dragons\n"
" ARTIST : Imagine Dragons, Kaskade\n"
" track : 1\n"
" disc : 1\n"
" TRACKTOTAL : 1\n"
" DISCTOTAL : 1\n"
" COPYRIGHT : undefined\n"
" LENGTH : 190\n"
" ISRC : USUM71705205\n"
" ITUNESADVISORY : 0\n"
" GENRE : Alternative\n"
" DATE : 2017-06-09\n"
" YEAR : 2017\n"
" BPM : 126\n"
" Duration: 00:03:10.89, start: 0.000000, bitrate: 1074 kb/s\n"
" Stream #0:0: Audio: flac, 44100 Hz, stereo, s16\n"
" Stream #0:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 1200x1200 [SAR 300:300 DAR 1:1], 90k tbr, 90k tbn, 90k tbc\n"
" Metadata:\n"
" comment : Cover (front)\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# 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