XeNote/posts/Code/JS/HTML Attribute Remover.md
2020-11-28 19:36:28 +03:00

23 lines
645 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

String şeklinde verilen HTML'deki tüm attributeları siler.
```js
let regex = /<\s*([a-z][a-z0-9]*)\s.*?>/gi
a.replace(regex, '<$1>')
```
<br/>
Örnek olarak a stringine bakalım
```js
let a = `<div class="ce-block"><div class="ce-block__content"><h1 class="ce-header" contenteditable="false" data-placeholder="Enter a header">Add a Title</h1></div></div><div class="ce-block"><div class="ce-block__content"><div class="ae-paragraph cdx-block" contenteditable="true" data-placeholder="Title">Content will be here</div></div></div>`
```
<br/>
Aşağıdaki komut bize temiz HTML'i verecektir.
```js
a.replace(regex, '<$1>')
```
#html-code