$re = '/(?:<TD CLASS="label")(?:.*>)(?s)(?<lbl>.*?)(?:<\/TD>).*?(?:<TD NOWRAP>).*?(?:type=)"(?<type>[^"]*)".*?(?:name=)"(?<name>[^"]*)".(?:title=)"(?<title>[^"]*)".*?(?:id=)"(?<id>[^"]*)".*?(?:value=)"(?<value>[^"]*)".*?(?:size=)"(?<size>[^"]*)".*?(?:maxlength=)"(?<maxlength>[^"]*)"*.*?<\/TD>$/im';
$str = '<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>';
$subst = "<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>";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$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 PHP, please visit: http://php.net/manual/en/ref.pcre.php