Post Reply 
Using $NEST
Jan. 03, 2009, 03:26 AM
Post: #1
Using $NEST
I'm trying to write a filter that removes certain tables.

An example table:
Code:
<table class="maintable">
    <tr>
        <td class="acell">a string</td>
    </tr>
</table>

I can match this table with this code:
Code:
<table*class=$AV(maintable)*>*</table>

The problem with that is that it doesn't work on nested tables:
Code:
<table class="maintable">
  <tr>
    <td class="acell">a string</td>
  </tr>
  <tr>
    <table>
      <tr>
        <td>another table</td>
      </tr>
    </table>
  </tr>
</table>

So I tried this:
Code:
$NEST(<table*class=$AV(maintable)*>,</table>)

This code only removes from the first opening table tag to the first closing table tag, and not the correct closing tag for the main table. Am I using $NEST incorrectly?
Add Thank You Quote this message in a reply
Jan. 03, 2009, 07:36 AM
Post: #2
RE: Using $NEST
Try:

Code:
<table[^>]++class=$AV(maintable)[^>]++>$INEST(<table,</table>)</table>

More information on $INEST:

http://proxomitron.info/45/help/Matching...html#INEST

BTW, Welcome! Cheers
Visit this user's website
Add Thank You Quote this message in a reply
Jan. 03, 2009, 08:02 AM
Post: #3
RE: Using $NEST
(Jan. 03, 2009 07:36 AM)Kye-U Wrote:  Try:

Code:
<table[^>]++class=$AV(maintable)[^>]++>$INEST(<table,</table>)</table>

More information on $INEST:

http://proxomitron.info/45/help/Matching...html#INEST

That works, thanks! I thought it may have been a bug in Proxomitron, I tried it in Proximodo and it crashed 4 times in the 15 minutes I had it installed.

I did read in the help file about NEST and INEST, but I didn't see that INEST also supported "inner match" (which I will need to test the tables contents before hiding it) because it wasn't used in the sample and I didn't notice it in the title with the syntax.

But, why use [^>]++ instead of *? Is * greedy? Shouldn't [^>]++class and *class be the same thing, assuming there is no > before class?

[^>]++class means any run of characters that isn't > up until class
*class means any run of characters up until class

Is that right?
Add Thank You Quote this message in a reply
Jan. 03, 2009, 08:04 AM
Post: #4
RE: Using $NEST
(Jan. 03, 2009 08:02 AM)Quaraxkad Wrote:  But, why use [^>]++ instead of *? Is * greedy? Shouldn't [^>]++class and *class be the same thing, assuming there is no > before class?

[^>]++class means any run of characters that isn't > up until class
*class means any run of characters up until class

Is that right?

Yup, you are correct. [^>]++ is just like *, but more specific in matching all characters except >.

I've ran into trouble using * instead of [^>]++, where, if the byte limit is huge, the * would actually "eat" beyond the > Wink
Visit this user's website
Add Thank You Quote this message in a reply
Jan. 03, 2009, 08:08 AM
Post: #5
RE: Using $NEST
(Jan. 03, 2009 08:04 AM)Kye-U Wrote:  Yup, you are correct. [^>]++ is just like *, but more specific in matching all characters except >.

I've ran into trouble using * instead of [^>]++, where, if the byte limit is huge, the * would actually "eat" beyond the > Wink

Ah-ha, that explains it, I usually use the max byte limit while testing.
Add Thank You Quote this message in a reply
Jan. 03, 2009, 11:11 AM
Post: #6
RE: Using $NEST
(Jan. 03, 2009 07:36 AM)Kye-U Wrote:  Try:

Code:
<table[^>]++class=$AV(maintable)[^>]++>$INEST(<table,</table>)</table>

A slight problem with that new code...

Lets say this is the table I want to match:
Code:
<table class="maintable">
  <tr>
    <td name="acell">match me</td>
  </tr>

  <tr>
    <td>
      <table>
        <tr>
          <td>another table</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
I only want to match tables where the text inside "acell" is "match me". How do I do that?
Add Thank You Quote this message in a reply
Jan. 03, 2009, 12:46 PM
Post: #7
RE: Using $NEST
<table[^>]++class=$AV(maintable)[^>]++>$INEST(<table,</table>)</table>

I'd recommend using [^>]+> instead of [^>]++> in such expressions, because gready + is faster than lazy ++.
In this case however, you can skip the red code, so:
Code:
<table[^>]++class=$AV(maintable)$INEST(<table,</table)</table >

I've used </table > (vs. </table> ) because...
Code:
<table
>
...is valid code and still used to work around an old Netscape bug.

(Jan. 03, 2009 11:11 AM)Quaraxkad Wrote:  A slight problem with that new code...

Lets say this is the table I want to match:
Code:
<table class="maintable">
  <tr>
    <td name="acell">match me</td>
  </tr>

  <tr>
    <td>
      <table>
        <tr>
          <td>another table</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
I only want to match tables where the text inside "acell" is "match me". How do I do that?

$NEST and $INEST accept an optional inner match: http://www.proxomitron.info/45/help/Matc....html#NEST
Code:
<table[^>]++class=$AV(maintable)$INEST(<table,*name=$AV(acell)>match me<*,</table)</table >
Add Thank You Quote this message in a reply
Jan. 03, 2009, 03:40 PM
Post: #8
RE: Using $NEST
Be careful when using $NEST 'cause it matches since the first opening tag it sees inside its byte limit.

Code:
$NEST(<table\s,*name="inner table"*,</table >)

would match:
Code:
<table name="outer table">
  ...
  <table name="inner table">
    ...
  </table>
  ...
</table>

And not would match only the next code how we could wish:
Code:
<table name="inner table">
    ...
  </table>

Trying to match the above using the code wich follows, could cause problems. So the best is what Kye-U and Sidki3k3 reccomends:
Code:
$NEST(<table\s[^>]++name="inner table"*,</table >)

To have a better idea on how nesting works, take a look to the test window of this filter, test it with the above code:
Code:
[Patterns]
Name = "testing nest"
Active = FALSE
Limit = 256
Match = "$NEST(<table\s(*>)\#,*name="inner table"*,</table >)"
Replace = "\@"
Add Thank You Quote this message in a reply
Nov. 14, 2009, 06:02 PM (This post was last modified: Nov. 14, 2009 06:34 PM by PAEz.)
Post: #9
RE: Using $NEST
Sorry to bring up an old thread, I know its all old and boring to alot of you.
But Im trying to learn this stuff and Im having a problem figuring out why
my nests arent working.
Following the advise on this thread I tried a couple of things and only one
worked and Im not sure why?

Does Work
EDIT: $NEST(<div,*id=$AV(watch-promoted-videos-container)*,</div >)
<div[^>]++id=$AV(watch-promoted-videos-container)$INEST(<div,</div)</div >
<div[^>]++id="watch-promoted-videos-container"$INEST(<div,</div)</div >
...and I know the last two are the same Wink


Doesnt work
$NEST(<div\s[^>]++id="watch-promoted-videos-container"*,</div >)
$NEST(<div\s(*>)\#,*id="watch-promoted-videos-container"*,</div >)
$NEST(<div[^>]++id="watch-promoted-videos-container",</div >)
...if they do anything at all it will cut off early. Im cool with using the above working one if I have to, but that last one of the doesnt work really does look like it should work to me and Im confused.

Test Code
Code:
<h2>Featured Videos</h2>
        <div id="watch-promoted-videos-container" class="watch-promoted-container grid-view">
                <div class="watch-promoted-vid">
                    

    <div class="video-entry ">
        <div class="v90WideEntry"><div class="v90WrapperOuter"><div class="v90WrapperInner"><a href="/cthru?key=R0xq9P6AML9DH8LkguVTpp-h0u9afan-t0tTU0QcQYOrep7bHmuvxvnY3lKt1-qbTeBL8GYcpRKBX7BEP5ot9_TRwtEnQACWN85qzklIrnT8UKjQ4IhEMyQfMaVK0FnAmQUhYcxN-jBol9kmM3MsUQd7LNJ4AxWUle5qnmrIb_Fi78ROlddISgAHKopKRzpALK8_zgx_emNEIMzP9MI9tg==" class="video-thumb-link" rel="nofollow"><img title="I SUCK- EPIC FAILZ!!" src="http://i4.ytimg.com/vi/71cGpZpe_DI/default.jpg" class="vimg90" qlicon="71cGpZpe_DI" alt="I SUCK- EPIC FAILZ!!"></a><div class="addtoQL90"><a href="#" ql="71cGpZpe_DI" title="Add Video to QuickList"><button title="" class="master-sprite QLIconImg" onclick="return yt.www.watch.quicklist.onQuickAddClick(this, this.parentNode.getAttribute('ql'), 'http://i4.ytimg.com/vi/71cGpZpe_DI/default.jpg', 'I SUCK- EPIC FAILZ!!')" onmouseover="yt.www.watch.quicklist.mouseOverQuickAdd(this)" onmouseout="yt.www.watch.quicklist.mouseOutQuickAdd(this)" onmousedown="yt.analytics.urchinTracker('/Events/VideoWatch/QuickList+AddTo')"></button></a><div class="hid quicklist-inlist"><a href="/my_quicklist">Added to <br> Quicklist</a></div></div><div class="video-time"><a href="/cthru?key=R0xq9P6AML9DH8LkguVTpp-h0u9afan-t0tTU0QcQYOrep7bHmuvxvnY3lKt1-qbTeBL8GYcpRKBX7BEP5ot9_TRwtEnQACWN85qzklIrnT8UKjQ4IhEMyQfMaVK0FnAmQUhYcxN-jBol9kmM3MsUQd7LNJ4AxWUle5qnmrIb_Fi78ROlddISgAHKopKRzpALK8_zgx_emNEIMzP9MI9tg==" rel="nofollow">4:36</a></div></div></div></div>
        <div class="video-main-content">

            <div class="video-mini-title"><a href="/cthru?key=R0xq9P6AML9DH8LkguVTpp-h0u9afan-t0tTU0QcQYOrep7bHmuvxvnY3lKt1-qbTeBL8GYcpRKBX7BEP5ot9_TRwtEnQACWN85qzklIrnT8UKjQ4IhEMyQfMaVK0FnAmQUhYcxN-jBol9kmM3MsUQd7LNJ4AxWUle5qnmrIb_Fi78ROlddISgAHKopKRzpALK8_zgx_emNEIMzP9MI9tg==" title="I SUCK- EPIC FAILZ!!" rel="nofollow">I SUCK- EPIC FAILZ!!</a></div>
            <div class="video-view-count">14,479 views</div>
            <div class="video-username"><a href="/user/Hughsnews">Hughsnews</a></div>
        </div>

        <div class="video-clear-list-left"></div>
    </div>

                </div>
                <div class="watch-promoted-vid">
                    

    <div class="video-entry ">
        <div class="v90WideEntry"><div class="v90WrapperOuter"><div class="v90WrapperInner"><a href="/cthru?key=RN8DefWFxFdyDHE9hlv2tGgucI1F_1kkorEy-UwugyhmJgD5Sj24LnEBVuGzIgfHsKtCy9KiZVpWPaqnC0qY14DU50HhwwEyQJ3rw2iiNGC_N1t-Eqivg1y8kiH9hlE95h1bmpcWzeoMW2HndXBukxSA_V3XZ29QYlRFn4KcWd5Zjj4IXdy_lBH7GSkc6wQBTjCOLsY50HRpL1aVmQ0t5Q==" class="video-thumb-link" rel="nofollow"><img title="WEAR A F*CKING CONDOM!!!" src="http://i3.ytimg.com/vi/2GX7Ia6YqWA/default.jpg" class="vimg90" qlicon="2GX7Ia6YqWA" alt="WEAR A F*CKING CONDOM!!!"></a><div class="addtoQL90"><a href="#" ql="2GX7Ia6YqWA" title="Add Video to QuickList"><button title="" class="master-sprite QLIconImg" onclick="return yt.www.watch.quicklist.onQuickAddClick(this, this.parentNode.getAttribute('ql'), 'http://i3.ytimg.com/vi/2GX7Ia6YqWA/default.jpg', 'WEAR A F*CKING CONDOM!!!')" onmouseover="yt.www.watch.quicklist.mouseOverQuickAdd(this)" onmouseout="yt.www.watch.quicklist.mouseOutQuickAdd(this)" onmousedown="yt.analytics.urchinTracker('/Events/VideoWatch/QuickList+AddTo')"></button></a><div class="hid quicklist-inlist"><a href="/my_quicklist">Added to <br> Quicklist</a></div></div><div class="video-time"><a href="/cthru?key=RN8DefWFxFdyDHE9hlv2tGgucI1F_1kkorEy-UwugyhmJgD5Sj24LnEBVuGzIgfHsKtCy9KiZVpWPaqnC0qY14DU50HhwwEyQJ3rw2iiNGC_N1t-Eqivg1y8kiH9hlE95h1bmpcWzeoMW2HndXBukxSA_V3XZ29QYlRFn4KcWd5Zjj4IXdy_lBH7GSkc6wQBTjCOLsY50HRpL1aVmQ0t5Q==" rel="nofollow">5:11</a></div></div></div></div>
        <div class="video-main-content">
            <div class="video-mini-title"><a href="/cthru?key=RN8DefWFxFdyDHE9hlv2tGgucI1F_1kkorEy-UwugyhmJgD5Sj24LnEBVuGzIgfHsKtCy9KiZVpWPaqnC0qY14DU50HhwwEyQJ3rw2iiNGC_N1t-Eqivg1y8kiH9hlE95h1bmpcWzeoMW2HndXBukxSA_V3XZ29QYlRFn4KcWd5Zjj4IXdy_lBH7GSkc6wQBTjCOLsY50HRpL1aVmQ0t5Q==" title="WEAR A F*CKING CONDOM!!!" rel="nofollow">WEAR A F*CKING CONDOM!!!</a></div>

            <div class="video-view-count">29,839 views</div>
            <div class="video-username"><a href="/user/Hughsnews">Hughsnews</a></div>
        </div>

        <div class="video-clear-list-left"></div>
    </div>

                </div>
                <div class="watch-promoted-vid">

                    

    <div class="video-entry ">
        <div class="v90WideEntry"><div class="v90WrapperOuter"><div class="v90WrapperInner"><a href="/cthru?key=dNZCgCzJyWLJZHNA8qJSzbRWpPzb7Oum0I5X-5ME4P8zME8l4tqH0nfRftv-tLJjBqwDE1oxE9OCTGDKrHeoZ85rq_9k9dOAqorhuHkgPvKL8FckByVT4L9vccehoYLowIttY5LP_lJOQ4xfvy3AwcTMnKVLoRrIQchVRtjIPsiqnDdqIqtin-TeMISh4WYFt_haotRTubUggUZpBl2xOg==" class="video-thumb-link" rel="nofollow"><img title="Youth: Time to be heard!" src="http://i1.ytimg.com/vi/dDmec2me55Q/default.jpg" class="vimg90" qlicon="dDmec2me55Q" alt="Youth: Time to be heard!"></a><div class="addtoQL90"><a href="#" ql="dDmec2me55Q" title="Add Video to QuickList"><button title="" class="master-sprite QLIconImg" onclick="return yt.www.watch.quicklist.onQuickAddClick(this, this.parentNode.getAttribute('ql'), 'http://i1.ytimg.com/vi/dDmec2me55Q/default.jpg', 'Youth: Time to be heard!')" onmouseover="yt.www.watch.quicklist.mouseOverQuickAdd(this)" onmouseout="yt.www.watch.quicklist.mouseOutQuickAdd(this)" onmousedown="yt.analytics.urchinTracker('/Events/VideoWatch/QuickList+AddTo')"></button></a><div class="hid quicklist-inlist"><a href="/my_quicklist">Added to <br> Quicklist</a></div></div><div class="video-time"><a href="/cthru?key=dNZCgCzJyWLJZHNA8qJSzbRWpPzb7Oum0I5X-5ME4P8zME8l4tqH0nfRftv-tLJjBqwDE1oxE9OCTGDKrHeoZ85rq_9k9dOAqorhuHkgPvKL8FckByVT4L9vccehoYLowIttY5LP_lJOQ4xfvy3AwcTMnKVLoRrIQchVRtjIPsiqnDdqIqtin-TeMISh4WYFt_haotRTubUggUZpBl2xOg==" rel="nofollow">3:53</a></div></div></div></div>
        <div class="video-main-content">
            <div class="video-mini-title"><a href="/cthru?key=dNZCgCzJyWLJZHNA8qJSzbRWpPzb7Oum0I5X-5ME4P8zME8l4tqH0nfRftv-tLJjBqwDE1oxE9OCTGDKrHeoZ85rq_9k9dOAqorhuHkgPvKL8FckByVT4L9vccehoYLowIttY5LP_lJOQ4xfvy3AwcTMnKVLoRrIQchVRtjIPsiqnDdqIqtin-TeMISh4WYFt_haotRTubUggUZpBl2xOg==" title="Youth: Time to be heard!" rel="nofollow">Youth: Time to be heard!</a></div>
            <div class="video-view-count">23,155 views</div>
            <div class="video-username"><a href="/user/Blade376">Blade376</a></div>

        </div>

        <div class="video-clear-list-left"></div>
    </div>

                </div>
            <div class="clearL"></div>
        </div>
    </div>
Add Thank You Quote this message in a reply
Nov. 14, 2009, 09:32 PM (This post was last modified: Nov. 14, 2009 10:47 PM by JJoe.)
Post: #10
RE: Using $NEST
The ending needs to be unique to the beginning.

(Nov. 14, 2009 06:02 PM)PAEz Wrote:  Does Work
EDIT: $NEST(<div,*id=$AV(watch-promoted-videos-container)*,</div >)

This is trying to match nests of <div to </div >.
Each <div has a matching </div >.
No <div to </div > consumes a <div without a </div >.

(Nov. 14, 2009 06:02 PM)PAEz Wrote:  $NEST(<div\s[^>]++id="watch-promoted-videos-container"*,</div >)
$NEST(<div[^>]++id="watch-promoted-videos-container",</div >)

These are trying to match nests of
<div id="watch-promoted-videos-container" to </div >
There isn't a nest of these. There is only one.
It starts with
<div id="watch-promoted-videos-container"
and ends with the first </div > found,
<a href="/my_quicklist">Added to <br> Quicklist</a></div>

(Nov. 14, 2009 06:02 PM)PAEz Wrote:  $NEST(<div\s(*>)\#,*id="watch-promoted-videos-container"*,</div >)

Here the code to be matched by the inner match doesn't contain
id="watch-promoted-videos-container"


I'd use $INEST for things like this.


HTH

Edit:
Added explanation for $NEST(<div\s(*>)\#,*id="watch-promoted-videos-container"*,</div >)
Add Thank You Quote this message in a reply
Nov. 15, 2009, 07:16 AM
Post: #11
RE: Using $NEST
THANK YOU soooooooooooo much! I get it now!
Thanks for taking the time to write such a detailed response. That was doing my head in, but with your reply and a couple of tests I get it now.
INEST all the way!
Add Thank You Quote this message in a reply
Nov. 15, 2009, 03:46 PM
Post: #12
RE: Using $NEST
(Nov. 15, 2009 07:16 AM)PAEz Wrote:  INEST all the way!

Well not all the way. Wink

JJoe Wrote:I'd use $INEST for things like this.

$INEST(), when the block of code begins with a rather unique string,
like <div id="watch-promoted-videos-container" class="watch-promoted-container grid-view">
Otherwise, $NEST() may be best.
Sometimes neither will work or is best.

Have fun
Add Thank You Quote this message in a reply
Post Reply 


Forum Jump: