D.B D.B - 23 days ago 4x
C# Question

Regular Expression to remove the first section from src attribute of an image

I need a regular expression able to replace the first section from src property of an image.

The image html looks like this

var example="<img src=\"data:image/jpeg;base64,/9j/....."

I need to replace all characters before the first comma (,) and replace it for an empty string, the "jpeg" section should be generic.

I tried that one but didn't work:

string res = example.Replace(@"/^data:image\/\w +\;base64,", "");

public class Test
    public static void Main()
        var example="<img src=\"data:image/jpeg;base64,/9j/.....";
        string res = Regex.Replace(example, "data:image\\/\\w+\\;base64\\,", "");

and the output is

<img src="/9j/.....