1

Hoping to extract these lines of Polyline object, but excluding those ones with the generic name (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>

I've used this

        MatchCollection m2 = Regex.Matches(html, "polyline_object name=\"*(.+?)\"", RegexOptions.Singleline);

but it gives me all of the names of above lines.

Apologize if I am not being clear, its my first time posting a question here. Thanks a lot!

These are the codes I am using which gives out both generic and the one I wanted. 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);
                }
            }
user131017
  • 11
  • 2

1 Answers1

1

This regex checks if the name doesn't start with Polyline and matches the whole line if this is the case:

^.*name="(?!Polyline\d{3}).*

With your provided input, it selects the 2 first lines.

See the demo

Explanation

  • ^.* matches any character from the start of the line
  • name=" matches literally this text
  • (?!Polyline\d{3}) asserts that name=" can't be followed by Polyline and 3 numbers to match
  • .* matches any character until the end of the line

Example

MatchCollection matches = Regex.Matches(html, @"^.*name=""(?!Polyline\d{3}).*", RegexOptions.Multiline);

foreach(Match match in matches)
{
    Console.WriteLine(match.Value);
}

See the example running

Community
  • 1
  • 1
Niitaku
  • 835
  • 9
  • 19
  • If you see the original codes, there are Polyline within the line of code that I wanted, I only want to excluded those with the name=Polylinexxx on my extraction – user131017 Feb 17 '17 at 23:15
  • @user131017 I updated my answer to match the 3 numbers after `Polyline`. The match is the same : the first two lines, those that don't have a name starting with `Polylinexxx`. – Niitaku Feb 17 '17 at 23:22
  • I've used MatchCollection in my code, what's the difference? OR would it be wise to do my match in the 1st round then do your match in the 2nd round? – user131017 Feb 17 '17 at 23:35
  • @user131017 I fixed it. I also added an example of values extraction. You'll get each matching line in the `foreach` with`match.Value`. – Niitaku Feb 17 '17 at 23:50
  • @user131017 I've added a running example link if it can help you. It shows the output of the code with the input text you provided. – Niitaku Feb 17 '17 at 23:58
  • Thanks, I see that it getting the lines that I want, would I be able to extract it to a checkedListBox? – user131017 Feb 18 '17 at 00:07
  • @user131017 It depends on what you want to do with the matched lines and ListBox. It can be another question to ask if you have trouble after searching and trying by yourself. – Niitaku Feb 18 '17 at 00:11