There is a string
/g/2559705e245a9d7faa2a4b9351d46e/? How to extract from it all that is between
'/g/' и '/?' ?
I try this, but something is not right:
let reg = url.match(/\/g\/(.*?)\//)[0]; There is a string
/g/2559705e245a9d7faa2a4b9351d46e/? How to extract from it all that is between
'/g/' и '/?' ?
I try this, but something is not right:
let reg = url.match(/\/g\/(.*?)\//)[0]; Character . selects any character at all, and a plus sign after it means “one or more matches”. If spaces are not exactly foreseen there, it was possible and (\S+) - matches any character except a space. And match() returns an array whose first element is the entire match, the second element is the first bracket in the regular line, then the second bracket, and so on. (expressions inside brackets are called Capture Group)
let str = 'kdls/g/2559705e2 45a9d7 faa2a4b9351d46e/?56a'; console.log( str.match(/(\/g\/)(.+)(\/\?)/)[0] ); console.log( str.match(/(\/g\/)(.+)(\/\?)/)[1] ); console.log( str.match(/(\/g\/)(.+)(\/\?)/)[2] ); // <-- Нужен этот console.log( str.match(/(\/g\/)(.+)(\/\?)/)[3] ); Try this - \d[A-Za-z0-9]+
Good service on regulars Regex
console.log("/g/2559705e245a9d7faa2a4b9351d46e/?".match('/g/(.*?)/')[1]); Source: https://ru.stackoverflow.com/questions/980971/
All Articles