How can I use RegExp?

My code:

let titleRegExp = new RegExp("<li class=“tv”><div class=“stui-vodlist__box”><a class=“stui-vodlist__thumb lazyload” href="(.)" title="(.)" data-original="(.)"><span class=“play hidden-xs”><span class=“pic-text text-right”>(.)<div class=“stui-vodlist__detail”><h4 class=“title text-overflow”><a href="." title=".">.*")

let titleMatch = html.match(titleRegExp)

let title = titleMatch[3]

return title

Just return one record.

I want to return a list.

Please fence your code in three backticks (```) on separate lines to make it easier to read.

You need to add *? after each dot, because a dot on its own only matches one character. The asterisk specifies to match as many characters as possible and the question mark then changes this to match as few characters as possible.


I’ve added parenthesis to the matches to indicate the content of the group. They are not part of the actual text that is matched!

Regex: text="(.)"

  • text="(1)"

doesn’t match:

  • text=""
  • text="foo bar"
  • text="foo" data="bar"

Regex: text="(.*)"

  • text="()"
  • text="(1)"
  • text="(foo bar)"
  • text="(foo" data="bar)"

Regex: text="(.*?)"

  • text="()"
  • text="(1)"
  • text="(foo bar)"
  • text="(foo)" data="bar" (notice the different closing parenthesis compared to the previous regex)

let titleRegExp1 = new RegExp("<li class=\"tv\"><div class=\"stui-vodlist__box\"><a class=\"stui-vodlist__thumb lazyload\" href=\"(.*)\" title=\"(.*)\" data-original=\"(.*)\"><span class=\"play hidden-xs\"></span><span class=\"pic-text text-right\">(.*)</span></a><div class=\"stui-vodlist__detail\"><h4 class=\"title text-overflow\"><a href=\".*\" title=\".*\">.*</a></h4></div></div></li>")


Get the newsest film.