I'm trying to use regular expressions in JS but I'm probably missing something because I can't get it to work. I have a couple of regular expression working fine in PHP (used with a preg_match) but when I use exactly the same expression in JS, I get no matched patterns.
Here is an example, I'm trying to parse the page:
https://www.coolblue.be/fr/rechercher?query=GTX+1060&trier=prix-les-moins-chers
My code:
var pattern = '/<a class=\"product__title js-product-title\" href=\"(.*)\" data-trackclickevent=\"(.*)\">[\n\r\s]+(.*)[\n\r\s]+<\/a>/gi';
var found = content.match(pattern);
The variable content contains the full source code of the page, I have dumped it in the console to make sure it was working and I see for example: (the code is dirty but I took it from the page mentionned above without changing anything)
<div class="product__titles"><div class="js-product-feature-title"></div><a class="product__title js-product-title" href="/fr/produit/654109" data-trackclickevent="Internal Search, Product, Oehlbach BTX 1000 (654109) - Product title">
Oehlbach BTX 1000
</a></div><div class="product__review-rating"><div class="review-rating alt-compact"><div class="review-rating--rating">
When I use https://regex101.com/ to test my regular expression, it also works but somehow in JS it doesn't.
Any idea of what I'm missing ?
thanks
Laurent