What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Chatevents, regex and itemLinks

geeekzor

Member
Joined
Jan 15, 2010
Messages
213
Reaction score
3
I can't find a solution anywhere, and regex makes my head hurt.

I've basically tried everything I can but I can't fix it.
PHP:
 |cff0070dd|Hitem:68356:0:0:0:0:0:0:652917696:85:0|h[Willful Ember Topaz]|h|r

Thats the itemlink/hyperlink we get, but we want the brackets and the name, not the retarded link that makes no sense and takes precious screen space.

I've been able to take the name out, but I can't hide the rest.

Any ideas?
 
Directly from my GliderRemoteCompat plugin:
Code:
using System.Text.RegularExpressions;

...

        private static readonly Regex
            ChatColorRegex = new Regex("\\|c[A-Za-z0-9]{6,8}"),
            ChatLinkRegex = new Regex("\\|H.*?\\|h");

        /// <summary>
        /// Removes all color and link escape sequences from a line of WoW chat.
        /// </summary>
        /// 

        /// <returns></returns>
        public static string RemoveChatFormatting(string str) {
            str = ChatColorRegex.Replace(str, "");
            str = ChatLinkRegex.Replace(str, "");
            str = str.Replace("|h", "");
            str = str.Replace("|r", "");
            return str;
        }

of course, regular expressions are still worth learning for your own knowledge in future situations.
 
Last edited:
Directly from my GliderRemoteCompat plugin:
Code:
using System.Text.RegularExpressions;

...

        private static readonly Regex
            ChatColorRegex = new Regex("\\|c[A-Za-z0-9]{6,8}"),
            ChatLinkRegex = new Regex("\\|H.*?\\|h");

        /// <summary>
        /// Removes all color and link escape sequences from a line of WoW chat.
        /// </summary>
        /// 

        /// <returns></returns>
        public static string RemoveChatFormatting(string str) {
            str = ChatColorRegex.Replace(str, "");
            str = ChatLinkRegex.Replace(str, "");
            str = str.Replace("|h", "");
            str = str.Replace("|r", "");
            return str;
        }

of course, regular expressions are still worth learning for your own knowledge in future situations.

Code:
const string s = "|cff0070dd|Hitem:68356:0:0:0:0:0:0:652917696:85:0|h[Willful Ember Topaz]|h|r  ";
var match = Regex.Match(s, @"(?<=\[)(.*?)(?=\])");
 if (match.Success)
     MessageBox.Show(match.Groups[0].Value);

I prefer using Regex since all we care about is within the brackets.
 
Back
Top