Help with reg ex / conditions

Hello,

I’m trying to use conditions to filter out unwanted alerts from my monitors. The monitors are following prices of some items but the issue when creating conditions is that the new text on the webpage usually contains also other unrelated numbers that are similar to the prices I’m interested in - meaning that simple “has number more/less than” -conditions don’t really help.

I understand reg ex condition is the more advanced way to filter unwanted results but the issue is that I have absolutely no experience in it. Would somebody with more knowledge be kind enough to give me example condition for the following case?

The webpage announces prices in form “€530.45 each” or “€98.20 each” (without quotation marks). I’d want to create a condition which causes prices between 50-200€ to alert. What would be the correct regular expression to achieve this?

(Also, if you can give examples for different price ranges like 29-236€ or 102-323€ so that I could learn to build these myself from the provided examples that would be greatly appreciated)

1 Like

Also additional question; I tried to monitor only listings that have 2-6 units available with expression “^[2-6] Available$” (without quotation marks), but looks like also listings with 1 unit cause alerts so my filter isn’t really working. Is this because the expression itself is wrong or for the reason that other text parts of the new single-unit-listing include numbers between 2-6 which causes the false alarm?

I’m sorry for the basic level questions - if my explanations were not sufficient, please tell me and I’ll try to explain better!

Hello @bfgmine, having multiple numbers in monitored text can make using conditions harder to use. Do you need to get alert on changes to all numbers or do you only need them to view in the Watchlist?

Hello ajitk, thanks for the reply. The website in question creates listings, which inherently have multiple numbers (price and other details) - my monitor checks the area on the webpage where all these active listings appear, so automatically all numbers on the listings are included. I’d like to filter out listings that are too expensive for me.

A separate challenge is to monitor listings (again having multiple numbers) with more than one unit available, which I tried to achieve with “^[2-6] Available$”, but apparently things are not that simple.

Any help you could offer with this? Thanks a lot!

Filtering a list is something we have been thinking about for some time when the website itself doesn’t offer a way to filter the search result. We don’t have an easy way to do filter lists right now.

We are making progress in this direction using data sources. It is not completely ready yet.

A workaround in the meantime is to use a JavaScript selector. JS can be used to modify the content in any way one needs to and then monitor the modified content. Just like other selectors, JS selectors need to select and return a list of elements. Following are some simple JS examples. In these examples, we use $ as the jQuery object.

  1. tracking changes to urls instead of their text in a page:

$('.table a').each((_, a) => a.textContent = a.href)

  1. Tracking changes to a style attribute of an element:

$('div.special').text( $('div.special').attr('style'))

  1. Formatting content before monitoring it. Note that scripts spanning multiple lines also work. One needs to make sure that the last expression evaluates to an element or a list of elements.
let text = document.body.textContent;
let monitoredText = text.replace('hello', 'hola');
documnet.body.textContent = monitoredText;
document.body;

The main technique for using the JS selector is that it evaluates to a list of elements in the DOM. Before returning the elements, JS can modify them in any way.

In your case, following pseudo code shows a potential solution:

function isGoodDeal(elItem) {
  let price = parseFloat($(elItem).find('.price').text());
  return price < 100;
}

let items = $('.list-items').toArray();
items = items.filter(el => isGoodDeal(el));
items;

Hope this helps. Let me know if you need help creating the script for the URL you are monitoring.

Cheers!

@alvaro89glez - the solution in case of bfgmine was using the JS selector. When the list has multiple numbers, conditions can’t be used effectively. The solution is to filter the list down using JS and then monitor the content for changes.