yckart
yckart

Reputation: 33408

RegExp to get unit from matrix strings

Say we've some strings like these and need the unit from them:

'rotate(90deg)' // 'deg'`
'rect(0 0 5px 5px)' // 'px'
'rgba(0, 0, 0, 0.5)' // ''

How can i accomplish that?

Upvotes: 1

Views: 266

Answers (1)

Magus
Magus

Reputation: 15104

This one should works :

/[0-9]+([^ ,\)`]*)/

Example :

/[0-9]+([^ ,\)`]*)/.exec('rect(5px 0px 0px 5px)')[1]; // 'px'

Upvotes: 1

Related Questions