# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".+left X:..(.+?)\n.+Y:..(.+?)\n.+\n.+\n.+:.(.+?)\n.+:.(.+?)\n"
test_str = ("\n"
"xwininfo: Window id: 0x4800024 \"Yebe\"\n\n"
" Absolute upper-left X: 100\n"
" Absolute upper-left Y: 164\n"
" Relative upper-left X: 10\n"
" Relative upper-left Y: 45\n"
" Width: 1600\n"
" Height: 1200\n"
" Depth: 24\n"
" Visual: 0x6e\n"
" Visual Class: DirectColor\n"
" Border width: 0\n"
" Class: InputOutput\n"
" Colormap: 0x4800022 (not installed)\n"
" Bit Gravity State: ForgetGravity\n"
" Window Gravity State: NorthWestGravity\n"
" Backing Store State: NotUseful\n"
" Save Under State: no\n"
" Map State: IsViewable\n"
" Override Redirect State: no\n"
" Corners: +100+164 -860+164 -860-76 +100-76\n"
" -geometry 1600x1200+90-66")
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