Search code examples
angular7

split url with comma and semicolon


I have image URL string like this

"Image1.jpg,Image2.jpg;Image3.jpg";

Now I want to split my imageurls with both comma and semicolon and store it into some array so how can I achieve that


Solution

  • In JS: use a regex for the split function separator:

    const url = "Image1.jpg,Image2.jpg;Image3.jpg";
    const arr = url.split(/[,;]+/);