# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[^\s]\s*END"
test_str = (" -- if this is a checkbox, \n"
" IF (@widget = 'Checkbox')BEGIN\n"
" EXECUTE [dbo].[home_save_slip_checkbox] @school_fk = @school_fk, @slip_fk = @res_output, @definition_field_fk = @definition_field_fk, @notes = '', @points = @points, @student_fk = @student_fk, @academic_year = @academic_year, @occurred_date = @occurred_date END\n"
" -- if this is an exclusion\n"
" IF (@widget = 'Exclusion')BEGIN\n"
" EXECUTE [dbo].[home_save_slip_exclusion] @slip_fk = @res_output, @school_fk = @school_fk, @student_fk = @student_fk , @ocean_user_fk = @ocean_user_fk, @definition_field_fk = @definition_field_fk, @points = @points, @exclusion_type = 'Internal', @exclusion_duration = 3, @start_date = @occurred_date , @notes = '', @d_of_e_reason_code = 'BU' , @reason = '', @academic_year = @academic_year, @category = 'FIXD', @occurred_date = @occurred_date , @definition_location_fk = @definition_location_fk END\n"
" -- if this is a detention\n"
" IF (@widget = 'Detention')BEGIN\n"
" EXECUTE [home_save_slip_detention] @slip_fk = @res_output, @school_fk = @school_fk, @student_fk = @student_fk , @definition_field_fk = @definition_field_fk, @detention_date = @occurred_date , @detention_location_fk = @definition_location_fk, @detention_duration = 30, @points = @points, @definition_slip_fk = @definition_slip_fk, @definition_subject_fk = @definition_subject_fk, @definition_class_fk = -1, @academic_year = @academic_year, @occurred_date = @occurred_date , @detention_reason = '', @detention_work_to_be_completed = '' END\n")
matches = re.finditer(regex, test_str)
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