I need to get a specific class with javascript. This class is bootstrap's grid : col-md-8
I need to get the number, I try this :
$class = $('div').attr('class');
$number = $class.match(/^col-md-./);
I'm real beginner in regex, please help me.
EDIT : $class may have more class like : 'col col-md-8 col-offset-md-8'
\d+ as pattern.
'col-md-8'.match(/\d+/)
// => ["8"]
'col-md-8'.match(/\d+/)[0]
// => "8"
\d match a digit character.+ is repetition modifier: makes previous pattern to match multiple (1 or more) timesUPDATE response to the the comment:
Using capturing group:
'other-class-1 col-md-8'.match(/col-md-(\d+)/)[1]
// => "8"
Use simply this: $class.substr(7)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With