# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[(bitrate:\ )] (\d*) [(kb\/s)]"
test_str = ("ffmpeg version git-2012-01-25-247d30a Copyright (c) 2000-2012 the FFmpeg developers\n"
" built on Jan 25 2012 16:56:18 with gcc 4.6.2\n"
" configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-x11grab --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --disable-ffserver\n"
" libavutil 51. 34.101 / 51. 34.101\n"
" libavcodec 53. 59.100 / 53. 59.100\n"
" libavformat 53. 30.100 / 53. 30.100\n"
" libavdevice 53. 4.100 / 53. 4.100\n"
" libavfilter 2. 60.100 / 2. 60.100\n"
" libswscale 2. 1.100 / 2. 1.100\n"
" libswresample 0. 6.100 / 0. 6.100\n"
" libpostproc 52. 0.100 / 52. 0.100\n"
"Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '3825402d75f04cadad96fa9f3af62c82.mp4':\n"
" Metadata:\n"
" major_brand : mp42\n"
" minor_version : 0\n"
" compatible_brands: mp41isom\n"
" creation_time : 2016-09-30 16:14:06\n"
" Duration: 00:00:15.04, start: 0.000000, bitrate: 1609 kb/s\n"
" Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1152x720 [SAR 1:1 DAR 8:5], 1611 kb/s, 30.30 fps, 30.30 tbr, 30k tbn, 60 tbc\n"
" Metadata:\n"
" creation_time : 2016-09-30 16:14:06\n"
" handler_name : VideoHandler\n"
"At least one output file must be specified\n")
matches = re.search(regex, test_str)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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