بازگشت به درس
این محتوا تنها در این زبان‌ها موجود است: English, Español, Français, Italiano, 日本語, 한국어, Русский, Türkçe, Українська, 简体中文. لطفاً به ما

Create a regular expression to find all (opening and closing) HTML tags with their attributes.

An example of use:

let regexp = /your regexp/g;

let str = '<> <a href="/"> <input type="radio" checked> <b>';

alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'

Here we assume that tag attributes may not contain < and > (inside quotes too), that simplifies things a bit.

The solution is <[^<>]+>.

let regexp = /<[^<>]+>/g;

let str = '<> <a href="/"> <input type="radio" checked> <b>';

alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'