Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.replace not removing characters

So I'm trying to convert PX to EM, but if a user enters 16px, instead of 16 I want to strip the PX. Here's what I'm using

.replace(/^EM+/i, '')

But for some reason it's not removing.

Here's a demo. Enter any value with PX, and you'll get NaN. Also is there a way to suppress the NaN so that then it won't show?


1 Answers

My understanding of this is that the ^ character specifies the start of the line, and the + character is specifying that there must be at least one of them... This example works:

.replace(/EM+/i, '')
like image 152
scrowler Avatar answered Jul 07 '26 02:07

scrowler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!