# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"public\s(\S*)\s(\S*)|=\s(\S*)|\"(.*?)\""
test_str = (" public bool ShouldMonitorSpoolFiles\n"
" {\n"
" get\n"
" {\n"
" return CheckMonitorSpoolFiles(CurrentConfiguration.POSSoftware);\n"
" }\n"
" }\n\n"
" public bool ExpectingEMFReceipt { get; set; }\n\n"
" public bool ForceEMFPrinting { get; set; }\n\n"
" public bool DisableEMFPrinting{ get; set; }\n\n"
" public bool OnlyValidDeliveryReceipt { get; set; }\n\n"
" public bool ShouldMonitorComPorts\n"
" {\n"
" get\n"
" {\n"
" return CheckMonitorCOMPorts(CurrentConfiguration.POSSoftware);\n"
" }\n"
" }\n"
" \n"
" public static bool CheckMonitorCOMPorts(string processorName)\n"
" \n\n"
" private string _CurrencyCode = \"GBP\";\n"
" public string CurrencyCode\n"
" {\n"
" get\n"
" {\n"
" return _CurrencyCode;\n"
" }\n"
" set\n"
" {\n"
" _CurrencyCode = value;\n"
" }\n"
" }\n\n"
" private string _DontStartasUser = \"\";\n"
" public string DontStartasUser\n"
" {\n"
" get\n"
" {\n"
" return _DontStartasUser;\n"
" }\n"
" set\n"
" {\n"
" _DontStartasUser = value;\n"
" }\n"
" }\n\n"
" public bool StartWatcherFromService { get; set; }\n\n"
" private string _OnlyStartasUser = \"\";\n"
" public string OnlyStartasUser\n"
" {\n"
" get\n"
" {\n"
" return _OnlyStartasUser;\n"
" }\n"
" set\n"
" {\n"
" _OnlyStartasUser = value;\n"
" }\n"
" }\n\n"
" public int FixedReceiptLineWidth { get; set; }\n\n"
" private string _extraNonFilteredCharactersRegex = \"\";\n"
" public string ExtraNonFilteredCharactersRegex\n"
" {\n"
" get\n"
" {\n"
" return _extraNonFilteredCharactersRegex;\n"
" }\n"
" set\n"
" {\n"
" _extraNonFilteredCharactersRegex = value;\n"
" }\n"
" }\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