Regex to parse image data URI

后端 未结 5 2202
野性不改
野性不改 2021-02-07 04:29

If I have :



        
5条回答
  •  青春惊慌失措
    2021-02-07 04:43

    EDIT: expanded to show usage

    var regex = new Regex(@"data:(?[\w/\-\.]+);(?\w+),(?.*)", RegexOptions.Compiled);
    
    var match = regex.Match(input);
    
    var mime = match.Groups["mime"].Value;
    var encoding = match.Groups["encoding"].Value;
    var data = match.Groups["data"].Value;
    

    NOTE: The regex applies to the input shown in question. If there was a charset specified too, it would not work and would have to be rewritten.

提交回复
热议问题