0

I have a string which may or may not contain a code for an emote, all of which begin the same: "auroraa1"

Such as:
"auroraa1Smile", "auroraa1Bye", "auroraa1Love"

I need to be able to grab the whole code for a given emote without any of the spaces before/after and alter it.

In a sentence such as:

"Hello Aurora! auroraa1Smile  How are you?"

I need to alter it to:

"Hello Aurora! [emote:4771491:auroraangel79Smile] How are you?"

Question:

How can I create a regex to capture the emote code from the source string: auroraa1Hi

My current code:

//read the twitchMsg and look for "auroraa1" which denotes an emote            string wordToFind = "auroraa1";            
string kickMsg = "NONE";            
kickMsg = CPH.GetGlobalVar<string>("s_msg");

// Find all occurrences of the wordToFind as a whole word            MatchCollection matches = Regex.Matches(kickMsg, $@"{wordToFind}", RegexOptions.IgnoreCase);

if (matches.Count > 0)            
{                
    CPH.SendMessage($"'{wordToFind}' found {matches.Count} times as a whole word.");                
    foreach (Match match in matches)                
    {                    
        CPH.SendMessage($"Found at index: {match.Index}");
    }            
}            
else
{                
    CPH.SendMessage($"'{wordToFind}' not found as a whole word.");            
}            

return true;

Here's the ouput I am getting:

'auroraa1' found 1 times as a whole word.  
Found at index: 28

I need output to say that it found 'auroraa1Smile'

New contributor
Aurora Zetanova is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • You mentioned in the Staging Ground that you have now solved this. So, if you wait a short time you can post your solution here (in the Answer box below) which may help others with a similar problem. Other people may also decide they can answer it another way too. Commented 3 hours ago
  • I tried to format your code. What's wrong with your formatting? Please make sure your code is readable with proper syntax coloring. If it does not work, please ask for help, try to be more accurate, but don't post it as is. Commented 3 hours ago
  • 4
    Also, you ask a question about Regular Expressions and basic replacements. Why your code sample is contaminated with CPH.SendMessage and other unrelated stuff? If you want to solve a problem with Regex, address just that. Please, 1) focus on exactly on issue, 2) read this: How to create a Minimal, Reproducible Example. Commented 3 hours ago
  • To help debug and test regular expressions, I recommend regex101.com Commented 2 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.