# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\bWARN\h+.*(?:\R(?!.*\h(?:WARN|INFO|OK)\h).*)*"
test_str = ("[C] L1250 WARN k2 bw34 Flex - Sockets:<16>, ThreadsPerCore:<1>\n"
"[C] L1250 WARN For abcd (analytical and transactional workloads). For 12s Systems and above, should be\n"
" disabled.\n"
"[C] L1250 INFO For abcd (analytical workloads), Hyperthreading should be enabled , 8s, 12s, 14d, 34t\n"
" d above.\n"
"[C] L1250 WARN Intel's Hyperthreading on 18+ Socket system disabled. Should be disabled urgently\n"
" fix it!\n"
"[C] L1300 OK CPU governors set as recommended\n"
"[C] L1250 WARN Intel's Hyperthreading on 8+ Socket system disabled.")
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