I'm working on a NodeJS script (launched from the CMD with the node command) getting me some HTML content in a string, in which I need to extract some data between a specific <div>
element. I'm having a hard time firguring why this portion of code doesn't give me the desired output.
const input = '<div class="some_class">Some data</div><div class="some_other_class">< class="some_other_other_class">...</div></div>'
const regex = new RegExp(/<div class="some_class"\>(.*?)<\/div>/g)
let obj = {
'tmp': input.search(regex),
}
console.log(obj) // outputs { tmp: 0}
console.log(input.search(/<div class="some_class"\>(.*?)<\/div>/g)) // outputs 0
const x = input.search(/<div class="some_class"\>(.*?)<\/div>/g)
console.log(x) // outputs 0
I know this seems a bit of a regular issue here, but I tried passing the Regex with string format (between single quotes '), passing it as a Regex (between delimiter /) and finally by defining a new RegExp element, but without success. I always happen to get 0 as an output.
However, when I test it on an online tool, it does match and capture the desired data in the group #1 : https://www.regextester.com/?fam=131034
I don't know if I'm missing something or if I'm doing something wrong, but after some hours spent on this issue, I'm quite struggling to get my ideas straight.