I found an elegant solution for what I'm trying to execute, which is the replacement of emotes in a string with a URL (it'll end up being an img tag once I figure this out. This solution was found here: iterating over a dictionary of Regex in C#. My issue is that when it reiterates over the already affected content block (output) it replaces the :/ in http:// with an emote URL.
I am getting my emotes from the Twitch API, which provides a regex for each emote and a URL for the image.
I'd like to replace all of the emotes in my Dictionary without overwriting instances contained in URLs. Is this possible? I thought this would be a simple effort but it's ended up spiraling way out of my realm of knowledge at this point.
public static string Replacements(string text)
{
string output = text;
foreach (KeyValuePair<string, string> item in dict1)
{
//here replace output again
output = Regex.Replace(output, item.Key, item.Value);
}
return output;
}
Edit: Sorry I didn't give enough info; still new to posting here. So the Regexes are fetched from the Twitch API for the streamer's emotes. Here's an example: Twitch API. This is a JSON string that provides the emotes, each emote containing a Regex identifier for the emote and a URL for the image of the emote.
"emoticons":[
{"width":24,"height":18,"regex":"\\:-?D","state":"active","subscriber_only":false,"url":"http://static-cdn.jtvnw.net/jtv_user_pictures/chansub-global-emoticon-9f2ac5d4b53913d7-24x18.png"}
{"width":24,"height":18,"regex":"\\:-?[\\\\/]","state":"active","subscriber_only":false,"url":"http://static-cdn.jtvnw.net/jtv_user_pictures/chansub-global-emoticon-374120835234cb29-24x18.png"}
...]
I'm pulling out just the regex and the URL for the image into a dictionary; key is regex and value is the URL. Using the code provided above, it replaces the :/ in http:// with the emote for :/
, so after I run the code I end up with the following:
httphttp://static-cdn.jtvnw.net/jtv_user_pictures/chansub-global-emoticon-374120835234cb29-24x18.png/static-cdn.jtvnw.net/jtv_user_pictures/chansub-global-emoticon-9f2ac5d4b53913d7-24x18.png
I hope this clarifies my predicament more.