Ich habe eine Zeichenfolge:Spiel exakt am nächsten Zeichenfolge mit Regex
Test.
<div>
<table style="color:blue;"><tbody><!--START SPACE COMMENTS SUMMARY-->
<tr><td colspan="2">SPACE COMMENTS SUMMARY</td></tr>
<tr><td style="min-width:200px;">Area/Room</td>
<td style="max-width:300px;text-align:left;">Comments</td>
</tr><tr><td style="min-width:200px;">Bathroom</td>
<td style="max-width:300px;text-align:left;">Some comment</td></tr>
<!--END SPACE COMMENTS SUMMARY--></tbody></table>
<div>
<table style="color:blue;"><tbody><!--START SPACE SUMMARY-->
<tr><td colspan="2">SPACE SUMMARY</td></tr><tr>
<td style="min-width:200px;">Space</td>
<td style="max-width:300px;text-align:right;">Installed Price</td></tr>
<tr><td style="min-width:200px;">Bathroom</td>
<td style="max-width:300px;text-align:right;">$2,355.97</td></tr>
<!--END SPACE SUMMARY--></tbody></table>
<br><br><br><div>Some text.</div></div></div>
ich mit regex auswählen möchten eine Tabelle, die Kommentare <!--START SPACE SUMMARY>
und <!--END SPACE SUMMARY-->
hat.
Ich versuchte mit @"<table.*?><tbody.*?><!--START SPACE SUMMARY>.*?<!--END SPACE SUMMARY--></tbody></table>"
, aber es wählt beide Tabellen in der Zeichenfolge.
EDIT: Meine Frage muss nicht genau mit HTML zu tun haben. Die gleiche Frage stehen wird, wenn ich einen String hatte:
some text blah blah one some text blah blah two.
Und ich will some text.*?two
some text blah blah two
mit einem Muster wählen.
Mögliches Duplikat von [RegEx-Übereinstimmungs-Öffnungs-Tags außer XHTML-eigenen Tags] (http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) –
Warum hier einen Regex verwenden und nicht 'IndexOf()' oder so? –
@Thomas kann Regex in IndexOf() eingefügt werden? Übrigens muss ich nicht wissen, ob die Zeichenfolge existiert, sondern den Inhalt auswählen. – kiriz