javascript - Optimizing Regex for removing classes -


i have function use remove classes element in javascript.

var reg = new regexp(cls+'(\\s|$)'); this.el.classname = this.el.classname.replace(reg, '').replace(/\s+$/g, ''); 

say have 3 classes on element

show hide color 

the first 2 removed along whitespace after it, third get's removed since there no whitespace after it, leaves space before it. string has whitespace on end. added second replace function rid of that, used in 1 circumstance

question: how rid of second replace function , have 1 regex want. thanks!

maybe handle cases.

 #  (?:\s(?:show|hide|color)|(?:show|hide|color)\s|\b(?:show|hide|color)\b)   (?:       \s        (?: show | hide | color )    |         (?: show | hide | color )       \s     |         \b                          # or ^       (?: show | hide | color )       \b                          # or $  ) 

Comments

Popular posts from this blog

c - CUDA code not processing if block properly -

Android Capture Image From Camera -

Define custom list-style-type in CSS -