In need your help for a simple javascript regex
javascript, regex
Solution
`\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) times
UPDATE response to the the comment:
Using capturing group:
'other-class-1 col-md-8'.match(/col-md-(\d+)/)[1]
// => "8"
Problem
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'