String error in js cutting array

let str = "https://img.codeshelper.com/upload/img/2021/03/02/y5ok3jewrp52423.jpg http://www.qqe.com/qwe/qwe.JPG"

console.log (str.match (/ (? < = ^ | .jpg) (. +?) .jpg / g));

the requirement is to cut the URL in array

use match (/? < = ^ | .jpg) (. +?) .jpg/ig) to cut

No problem in chrome, but errors will be reported in firefox and safari

firefox error message is SyntaxError: invalid regexp group
safari error message is Invalid regular expression: unrecognized character after (?

checked that it is possible that js does not support it? < =

how to rewrite this paragraph is better?

or if you have a better way to cut strings, you can also put forward

.
Mar.02,2021

if you are sure it starts with http,https, you can use

str.match(/(http|https):\/\/.+?\.(jpg|JPG|png|PNG)/)

1, cut with split

function a(str){
    var arr = []
    var strs = str.split(/(\.jpg|\.JPG|\.png|\.PNG)/)
    strs.map((item,i)=>{
        if(i%2 == 0){
            arr.push(strs[i-1]+item)
        }
    })
    return arr
}
console.log(a(str))

2. Use replace

function b(str){
    var index = 0,
        arr = [];
    str.replace(/(\.jpg|\.JPG|\.png|\.PNG)/g,(match, p1, i, p3, offset, string)=>{
        arr.push(str.substring(index,i+match.length));
        index = i+match.length;
    })
    return arr
}
console.log(b(str))
Menu