import Foundation
let pattern = #"(?:<TD CLASS="label")(?:.*>)(?s)(?<lbl>.*?)(?:<\/TD>).*?(?:<TD NOWRAP>).*?(?:type=)"(?<type>[^"]*)".*?(?:name=)"(?<name>[^"]*)".(?:title=)"(?<title>[^"]*)".*?(?:id=)"(?<id>[^"]*)".*?(?:value=)"(?<value>[^"]*)".*?(?:size=)"(?<size>[^"]*)".*?(?:maxlength=)"(?<maxlength>[^"]*)"*.*?<\/TD>$"#
let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive])
let testString = #"""
<tr>
<TD CLASS="label" NOWRAP VALIGN="MIDDLE">
Average_No_of_Direct_Employees:
</TD>
<TD NOWRAP>
<INPUT CLASS="valueEditable" TYPE="text" NAME="_1_1_10_1" TITLE="Average_No_of_Direct_Employees" ID="_1_1_10_1" VALUE="[LL_FormTag_1_1_10_1 /]" SIZE="20" MAXLENGTH="20" ONCHANGE="markDirty();">
</TD>
</TR>
<!-- End File: datefield.html (End - _1_1_9_1) -->
</TD>
</TR>
<TR CLASS="horizontalCellDivider" >
<TD CLASS="labelHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/spacer.gif" WIDTH="1" BORDER="0"></TD>
<TD CLASS="valueHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/tbl-divider-hor.gif" WIDTH="3" BORDER="0"></TD>
</TR>
<TR>
<TD CLASS="label" NOWRAP VALIGN="MIDDLE">
Average_No_of_Direct_Employees:
</TD>
<TD NOWRAP>
<INPUT CLASS="valueEditable" TYPE="text" NAME="_1_1_10_1" TITLE="Average_No_of_Direct_Employees" ID="_1_1_10_1" VALUE="[LL_FormTag_1_1_10_1 /]" SIZE="20" MAXLENGTH="20" ONCHANGE="markDirty();">
</TD>
</TR>
<TR CLASS="horizontalCellDivider" >
<TD CLASS="labelHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/spacer.gif" WIDTH="1" BORDER="0"></TD>
<TD CLASS="valueHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/tbl-divider-hor.gif" WIDTH="3" BORDER="0"></TD>
</TR>
<TR>
<TD CLASS="label" NOWRAP VALIGN="MIDDLE">
Average_No_of_SubContractors_on-site:
</TD>
<TD NOWRAP>
<INPUT CLASS="valueEditable" TYPE="text" NAME="_1_1_11_1" TITLE="Average_No_of_SubContractors_on-site" ID="_1_1_11_1" VALUE="[LL_FormTag_1_1_11_1 /]" SIZE="20" MAXLENGTH="20" ONCHANGE="markDirty();">
</TD>
</TR>
<TR CLASS="horizontalCellDivider" >
<TD CLASS="labelHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/spacer.gif" WIDTH="1" BORDER="0"></TD>
<TD CLASS="valueHorizontalDivider" COLSPAN="1"><IMG HEIGHT="1" ALT="" SRC="/img/tbl-divider-hor.gif" WIDTH="3" BORDER="0"></TD>
</TR>
<TR>
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = ####"<div class="medium-6 columns">\n <label>${lbl} <!--### INPUT EXAMPLE ### -->\n <input type="${type} <" NAME="${name}" TITLE="${title}" ID="${id}" VALUE="${value}" SIZE="${size}" MAXLENGTH="${maxlength}" ONCHANGE="markDirty();>\n </label>\n</div>"####
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression