Skip to content

Instantly share code, notes, and snippets.

@lucasvazq
Last active June 21, 2020 18:57
Show Gist options
  • Save lucasvazq/54b292c00204d2c9c3d2e46ba4ee608d to your computer and use it in GitHub Desktop.
Save lucasvazq/54b292c00204d2c9c3d2e46ba4ee608d to your computer and use it in GitHub Desktop.
HTML5 Regex start tags

Match Html5, non XML, start tags or self closing tags

Only for fun

<[^=\'"\\\/> ]+( ( *([^=\'"\\\/> ]+ *= *(("([^"]?(<!--(\s|\S)*-->)*[^"]+)*")|(\'([^\']?(<!--(\s|\S)*-->)*[^\']+)*\')|(([^\'" \>]?(?!\/>)[^=\'" \/\>]+)+))|([^=\'" \>]?(?!\/>)[^=\'" \/\>]+)+|(<!--(\s|\S)*-->)))*)? *>

Test cases

Asserts

A - 19 steps

<p >some text

B - 248925 steps 👎

<h1 <!--what'

sup -->
class = "
e"
>

C - 107 steps

<link rel=icon type='image\>
 /x-icon'    >

D - 7 steps

 Hi <br>

E - 103 steps

<wĔbC0mponent ✔️     titlĔ="web\nComp"data-attr=123 disabled✔️>
Fail

A - 2 steps

< p >some text

B - 6 steps

some text <class="title">

C - 3193 steps

<link rel=/ico/>n>

D - 6 steps

Hi<br/>

E - 2 steps

</wĔbC0mponent✔️>
@lucasvazq
Copy link
Author

Why Fails.C fails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment