Regular expressions - JavaScript | MDN

To practice more JavaScript, I choose to do this thing:

Screenshot 2024-09-14 at 13.18.24.png

As I opened the example, I could understand the general logic but still confused about the detailed syntax. And I asked chatGPT, especially this line, since I am new to split() and regex:

words = s.split(/(\\W+)/

GPT is good at explaining things.

Screenshot 2024-09-14 at 13.20.45.png

Screenshot 2024-09-14 at 13.20.59.png

Created resetHighlight function

Defined a data-original attribute to store the original text

Screenshot 2024-09-15 at 10.25.48.png

Show the index of the text when hovered

Screenshot 2024-09-15 at 10.44.28.png

Link here: https://editor.p5js.org/cy1503/sketches/xkIYI_l6-