javascript - help with regular interception and matching problems
習慣沉默
習慣沉默 2017-07-05 10:53:53
0
6
966
src\main\webapp\static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png

I want to intercept the string starting from static. How should I write the regular expression? grateful

That is, static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png

In addition, since the first half of the URL may change, it is best to use regular ones

習慣沉默
習慣沉默

reply all(6)
小葫芦
var str='src\\main\\webapp\\static\\ca7ecd95-aa95-4da8-b369-92b66b566958\\icon.png';
alert(str.replace(/^.*?(static.*?)$/ig, '$1'));
刘奇

split('static')[1] Is this the case? Or do I need to use regular rules?

学霸

str.slice(str.search(/static/));

phpcn_u1582

You should use static.* for regular expressions. The following is the reference code

const regex = /static.*/g;
const str = `src\main\webapp\static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
ringa_lee

'srcmainwebappstaticca7ecd95-aa95-4da8-b369-92b66b566958icon.png'.split('static')[1]

曾经蜡笔没有小新
'src\main\webapp\static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png'.match(/static.*/)

// Output: 
[
  "static\ca7ecd95-aa95-4da8-b369-92b66b566958\icon.png"
]

Highlights of this question:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template