Search code examples
javascriptregexgetsubstring

how to get word from string via regexpt


I have string and i need to get word from symbol till space for example:

 const str = "/count 50"

I need to get "count" from string. So I probably need to cut first symbol till first space.


Solution

  • var r = '/count 50'.match(/\/([A-Za-z]+)/)[1];
    
    console.log(r)