0

I want use regular expression to replace html attribute ng-model='model.xxx' to ng-model='model.newname.xxx', but I don't need replace attribute between <tbody> <tr class='template' ng-repeat='model in model.child'></tr></tbody>;

<table width="592" height="842" border="1" align="center">
      <tr>
        <td align="center" colspan="2" width="16%">serve_resource_name</td>
        <td colspan="8"><input class="text" name="serve_resource_name" type="text" ng-model="model.serve_resource_name" id="serve_resource_name" title="serve_resource_name" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
      </tr>
      <tr>
        <td align="center" rowspan="4" width="8%">clinet</td>
        <td align="center" style="width:8%">system</td>
        <td colspan="3"><input class="text" name="system" type="text" ng-model="model.system" id="system" title="系统" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
        <td align="center" colspan="2" width="16%">IP</td>
        <td colspan="3"><input class="text" name="ip" type="text" ng-model="model.ip" id="ip" title="IP" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
      </tr>
      <tr>
        <td align="center">username</td>
        <td colspan="3"><input class="text" name="username" type="text" ng-model="model.username" id="username" title="用户名" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
        <td align="center" colspan="2" width="16%">password</td>
        <td colspan="3"><input class="text" name="password" type="text" ng-model="model.password" id="password" title="密码" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
      </tr>
      <tr>
        <td align="center" width="16%">time_limit</td>
        <td colspan="8"><input class="text" name="time_limit" type="text" ng-model="model.time_limit" id="time_limit" title="期限" value="" maxlength="" plugins="text" fallowblank="false" datatype="text"/></td>
      </tr>``

       <tr>
            <td align="center" width="8%" height="150px">flow control</td>
            <td colspan="9" style="padding:0; vertical-align:top;">
            <div style="overflow:auto; height:150px;">
                <table id="697e5afad8e540659efb412ea0347b5d" name="flowControl" fnote="flow control" fdatatype="1" plugins="childtable" border="1" cellspacing="0" cellpadding="0">
                    <thead>
                        <tr class="firstRow">
                            <td align="center" width="24%">time_quantum</td>
                            <td align="center" width="24%">interval</td>
                            <td align="center" width="24%">time_interval_min</td>
                            <td align="center" width="24%">visit_count_limit</td>
                            <td align="center"  ><div class="img-add" ng-click="imgAdd('model.table')"></div></td>
                      </tr>
                    </thead>
                    <tbody>
                        <tr class="template" ng-repeat="model in model.child">
                            <td ><input name="time_start" type="text" ng-model="model.time_start" id="time_start" title="time_start" value="" maxlength="" placeholder="8:00"/>-<input name="time_end" type="text" ng-model="model.time_end" id="time_end" title="time_end" value=""placeholder="22:00"/></td>
                            <td ><input name="time_interval_count" type="text" ng-model="model.time_interval_count" id="time_interval_count" title="time_interval_count" value="" /></td>
                            <td ><input class="text" name="visit_count_limit" type="text" ng-model="model.visit_count_limit" id="visit_count_limit" title="visit_count_limit" value="" "/></td>
                            <td ><input class="text" name="visit_flux_limit" type="text" ng-model="model.visit_flux_limit" id="visit_flux_limit" title="visit_flux_limit" value="" /></td>
                        </tr>
                    </tbody>

                </table></div>
            </td>
        </tr>
      <tr>
        <td align="center" width="8%">remark</td>
        <td colspan="9">
         <div class="word-text"><textarea class="bor" id="remark" name="remark" ng-model="model.remark" title="remark" maxlength="" plugins="textarea" fallowblank="false"></textarea></div>
        </td>
      </tr>
      </table>`
william
  • 11
  • 2
  • Why are you trying to do this? –  May 16 '16 at 03:02
  • 2
    Someone's gotta post it: [*You can't parse \[X\]HTML with regex…*](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – RobG May 16 '16 at 03:21
  • Now that the question has been edited to give the full context, I can see that you're better off traversing the DOM and replacing the values that way instead of using regex. I've deleted my answer because using regex in your case is definitely not a good idea (and is generally frowned upon for HTML parsing anyway). – timolawl May 16 '16 at 03:29
  • If you want to do that with a regex, you just need to know that it is likely to fail in case of nested tags and in case the document is huge. The regex you can try (but should not use) is `.replace(/(PATTERN_YOU_NEED_TO_KEEP)|PATTERN_TO_DELETE/g, "$1")`. – Wiktor Stribiżew May 16 '16 at 06:57

0 Answers0