Let's say I have a string form-step-45. How to omit the form-step- and retrieve only the number using jQuery? The number varies and can be from 1 to ∞.
            Asked
            
        
        
            Active
            
        
            Viewed 49 times
        
    -6
            
            
         
    
    
        Rafff
        
- 1,510
- 3
- 19
- 38
- 
                    4Do you mean using JavaScript? There's no need to use jQuery for that. Is the `form-step-` constant? – BenM Oct 20 '14 at 15:19
- 
                    3What's a likely and realistic upper bound for that number? If they get too large you're going to run into issues storing it in memory. – Anthony Grist Oct 20 '14 at 15:19
- 
                    1Have you tried anything? – j08691 Oct 20 '14 at 15:19
- 
                    possible duplicate of [How do I split a string, breaking at a particular character?](http://stackoverflow.com/questions/96428/how-do-i-split-a-string-breaking-at-a-particular-character) – Abhi Oct 20 '14 at 15:21
- 
                    this question sure shows a complete lack of research effort – charlietfl Oct 20 '14 at 15:26
5 Answers
0
            
            
        This should do it:
    var k = 'form-step-45';
    var num = k.split('-').pop();    
    var k = 'form-step-45';
    var num = k.split('-').pop();
    alert( num ); 
    
    
        PeterKA
        
- 24,158
- 5
- 26
- 48
-1
            
            
        try this
var str = "form-step-45" ;
str = str.replace("form-step-" , "");
 
    
    
        Hossam Aldeen Ahmed
        
- 772
- 1
- 8
- 20
- 
                    it will of course return the number "45" he didn't sayed he want it as integer – Hossam Aldeen Ahmed Oct 20 '14 at 15:33
 
     
    