Is there an equivalent in jQuery to PHP's `preg_replace()`?

后端 未结 3 1679
无人及你
无人及你 2021-01-17 11:13

Say I have the following:


This path could be anything, we basically want to get the

3条回答
  •  日久生厌
    2021-01-17 11:36

    You could use replace() which is like PHP's preg_replace() (it too accepts a PCRE, with some limitations such as no look behinds)...

    str.replace(/.*\//, '')
    

    jsFiddle.

    Alternatively, you could use...

    str.split('/').pop();
    

    jsFiddle.

提交回复
热议问题