Search code examples
regexskip

Skip a specific number of characters, and return the desired output, using regex


Here is the code:

%2Fdl%2Fac8ee4c1b1ff6f713d3b19969d6c24e3%2F52d2eae9%2Fff2c0ea38304a00b01c3e573babcde109f

What I need is return in 3 separate regular expressions:

  1. ac8ee4c1b1ff6f713d3b19969d6c24e3 that's an easy one: dl%2F(.*?)%2F

  2. 52d2eae9 -- currently I'm using dots (.) to skip the undesired chars, but looking for a slicker way, if possible

  3. ff2c0ea38304a00b01c3e573babcde109 -- same as (2)


Solution

  • If I misunderstood you and you don't need three seperate expressions, then this one will capture all three items in a capturing group:

    dl%2F(.+)%2F(.+)%2F(.+)
    

    If there really is a need for three seperate expressions, then you may use them like

    1. dl%2F(.+)%2F
    2. dl%2F.+%2F(.+)%2F
    3. dl%2F.+%2F.+%2F(.+)
      or
      .*%2F(.+?)$ (Note: $ marks the end of the input)