Regular Interception of the Second/Later Content
Another example is/haha/yr-1-k
What is uncertain is the second / the following: there may be English, numbers, and short horizontal lines (the rest are not).
To be sure, the first character of the intercepted string must be /;
And there must be a bunch of English between them.
Ordinary single interception, multiple interception, or by intercepting two / between characters and replacing the original string.
howeverWhat’s the best performance?
Six Available Answers: Performance Test Results—— Chrome 53
Border Town: about 5,790,000 executions per second;
Xzavier: about 5,390,000 executions per second;
Questioning the Central Plains: about 4,310,000 executions per second;
Agree and accept: about 6,590,000 executions per second;
Hping: about 4,730,000 executions per second;
A fool is not foolish: about 2,790,000 executions per second;
Consensus and acceptance
.split('/')The method has the best performance.
Split is OK, the simplest is it.~
'/test/gagaga'.split('/') "gagaga" '/hahaha/yr-1-k'.split('/') "yr-1-k"
We can confirm that the first character of the intercepted string must be /; and the first character between the two must be a string of English, anyway, we need to use the string method, with fewer steps, fewer code, and the corresponding performance will be good.
As you said:
'/test/gagaga'.replace(/\/.+\//,''); //"gagaga" '/hahaha/yr-1-k'.replace(/\/.+\//,''); //"yr-1-k"
- Zero Width Assertion Back Matching
execMethod, Partial Matching