I have the following code:
var html = "<div class='test'><b>Hello</b> <i>world!</i></div>";
var results = html.match(/<(\/?) (\w+) ([^>]*?)>/);
About the three sets of parenthesis:
First mean: forward slash or nothing.
Second mean: one or more alphanumeric characters.
Third mean: anything but ‘>’ then I don’t understand the ‘*?’ !
Also how do I interpret the fact that there are three sets of parenthesis separated by white spaces?
Regards,
An asterisk (
*) means match the preceding bit zero or more times. The preceding bit is[^>], meaning anything but a >. As @user278064 says, the?is redundant. It’s meant to make the*non-greedy, but there’s no need as the[^>]already specifies what the*should refer to. (You could replace[^>]with a.(full-stop/period) which would match any character, then the?would make sure it matches anything until>.)As for the spaces, they shouldn’t be there… they literally match spaces, which I don’t think you want.