Skip to content
Advertisement

Regular expression to convert html class to attribute

Is there any way to use regular expression alone or with help of javascript to do the following

from

JavaScript

to

JavaScript

Advertisement

Answer

This regular expression will match what you describe, regardless of the position of “type-xxx” in class attribute

JavaScript

Combining with a string replace

JavaScript

this will yield the result

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement