Can you grab last item in selector list?

When you have multiple matches for a selector, I know you can grab something other than the first one with list[n]. Is there a way to grab the last one regardless of the list size though? I have a varying number of elements that changes at any given moment and I always need to grab the last element only. I tried something like this but it breaks from recursion. I only need the last element in the list, I just never know how many of this element will be present at any given time. Is this doable? Is there a way to dynamically input {count} here? Thanks for any assistance.

{count=count({site: text; selector=.eph_c26b64; multiple=yes})}
{id=catch(extractregex({site: text; selector=.eph_c26b64; multiple=yes}[{count}], "User ID: (.*)"), 0); trim=yes}

Actually, I think I may have figured it out. :slight_smile: I think it may have been to do with my variable naming being count and using count() plus the {} in the [variable].

This works.

{s_count=count({site: text; selector=.eph_c26b64; multiple=yes})}
{id=catch(extractregex({site: text; selector=.eph_c26b64; multiple=yes}[s_count], "User ID: (.*)"), 0); trim=yes}

2 Likes

While we're on this, we can make it a bit easier to read like this :slightly_smiling_face:

{site_data={site: text; selector=.eph_c26b64; multiple=yes}}
{s_count=count(site_data)}
{last_item=site_data[s_count]}
{id=catch(extractregex(last_item, "User ID: (.*)"), 0); trim=yes}

1 Like

Thank you! This is definitely a bit more elegant. :slight_smile: