希望提取Polyline对象的这些行,但不包括具有通用名称的那些(Polyline)
</polyline_object><polyline_object name="ECC018" kind="PolyLineObjectX"><name>ECC018</name><point length="3"> -312.52499389648435 62.385520935058598 39.511650085449216 </point><point length="3"> -309.38851928710938 62.611492156982426 39.349102020263674 </point>
</polyline_object><polyline_object name="STEP (25)" kind="PolyLineObjectX"><name>STEP (25)</name><point length="3"> -313.64254760742189 62.275627136230464 39.640590667724608 </point><point length="3"> -312.55957031249997 62.376560211181645 39.627662658691405 </point><point length="3"> -312.7188415527344 64.059944152832026 39.638328552246093 </point><point length="3"> -313.1711730957031 64.028800964355469 39.651771545410157 </point>
</polyline_object><polyline_object name="Polyline000 (3)" kind="PolyLineObjectX"><name>Polyline000 (3)</name><point length="3"> 2.6950883865356445 44.503276824951174 37.697837829589843 </point><point length="3"> -75.466423034667968 47.88733673095703 39.203029632568358 </point><point length="3"> -111.57073211669922 43.517368316650394 39.25448226928711 </point><point length="3"> -118.22566986083984 37.122959136962893 39.077449798583987 </point><point length="3"> -122.02384185791014 27.188623428344726 38.753135681152346 </point><point length="3"> -121.8035888671875 22.215513229370118 38.595668792724608 </point><point length="3"> -120.69635772705078 10.44062900543213 38.525798797607424 </point><point length="3"> -119.39793395996093 -1.391708493232727 38.479351043701171 </point><point length="3"> -111.05265045166016 -0.50858658552169798 38.464771270751955 </point><point length="3"> -109.4428482055664 -13.537007331848144 38.171108245849606 </point>
</polyline_object><polyline_object name="Polyline001 (3)" kind="PolyLineObjectX"><name>Polyline001 (3)</name><point length="3"> -129.52786254882813 166.05583190917968 40.779067993164064 </point><point length="3"> -125.67138671875 156.94186401367187 40.774162292480467 </point><point length="3"> -113.06429290771485 116.86449432373046 40.768569946289062 </point><point length="3"> -113.13454437255859 116.2726516723633 38.973728179931642 </point><point length="3"> -112.24276733398437 113.77603149414062 38.96575927734375 </point><point length="3"> -111.49858856201173 114.01608276367187 38.981853485107424 </point><point length="3"> -106.42765045166016 100.83160400390626 39.037631988525389 </point><point length="3"> -107.75248718261718 99.620536804199219 38.996852874755859 </point><point length="3"> -103.67796325683594 86.614151000976563 39.067848205566406 </point><point length="3"> -116.04350280761718 74.861045837402342 39.25809097290039 </point><point length="3"> -122.38642120361328 74.47401428222656 39.252414703369139 </point><point length="3"> -122.78543853759765 74.44397735595703 39.25035858154297 </point><point length="3"> -122.8647918701172 73.826538085937498 42.272285461425779 </point><point length="3"> -119.59778594970704 41.25065612792969 42.267509460449216 </point><point length="3"> -175.69285583496093 35.908145904541018 42.259567260742189 </point><point length="3"> -188.11454772949219 63.682300567626957 42.2263069152832 </point><point length="3"> -218.66964721679686 60.854137420654298 42.268066406249997 </point><point length="3"> -221.23516845703126 88.376388549804685 41.072391510009766 </point><point length="3"> -225.47735595703126 88.032569885253901 41.053840637207034 </point><point length="3"> -229.76127624511718 131.20693969726563 40.885227203369139 </point><point length="3"> -187.65846252441405 152.36131286621094 40.93291473388672 </point><point length="3"> -180.48707580566406 149.78179931640624 40.9343147277832 </point><point length="3"> -129.52786254882813 166.05583190917968 40.779067993164064 </point>
</polyline_object><polyline_object name="Polyline002 (3)" kind="PolyLineObjectX"><name>Polyline002 (3)</name><point length="3"> -112.50492858886718 115.78641510009766 38.953884124755859 </point><point length="3"> -111.31856536865234 112.05601501464843 38.973159790039066 </point>
我用过这个
MatchCollection m2 = Regex.Matches(html, "polyline_object name=\"*(.+?)\"", RegexOptions.Singleline);
但它给了我上面所有行的名字。
道歉,如果我不清楚,这是我第一次在这里发帖提问。非常感谢!
这些是我正在使用的代码,它给出了泛型和我想要的代码。 MatchCollection m2 = Regex.Matches(html,“polyline_object name = \”*(。+?)\“”,RegexOptions.Singleline);
foreach (Match m in m2){
if (m.Groups[1].Value != "Polyline(.+?)"){
string line = m.Groups[1].Value;
drawlines.Add(line);
}
}
答案 0 :(得分:1)
此正则表达式检查名称是否不以Polyline
开头,如果是这样,则匹配整行:
^.*name="(?!Polyline\d{3}).*
使用您提供的输入,它会选择2个第一行。
^.*
匹配行首name="
字面上符合此文字(?!Polyline\d{3})
断言name="
后面不能跟Polyline
和3个数字匹配.*
匹配任何字符,直到行尾MatchCollection matches = Regex.Matches(html, @"^.*name=""(?!Polyline\d{3}).*", RegexOptions.Multiline);
foreach(Match match in matches)
{
Console.WriteLine(match.Value);
}