Shoutbox

[Howto] Get Personalized status - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Howto] Get Personalized status (/showthread.php?tid=62239)

[Howto] Get Personalized status by J-Thread on 07-01-2006 at 12:44 PM

A little function that I wrote, I think this might be usefull for others.

code:
function PersonalizedStatus() {
   var myRegExp = /^(.*)(\xA0\{(.+)\})$/ig;
   return myRegExp.exec(Messenger.MyName);
}

This function will return null when there is no personalized status, else it will return an array with the following elements:

0 --> The whole display name including the personalized status
1 --> The display name without the personalized status
2 --> The personalized status part, including the { } and the special character before it
3 --> The personalized status without the { } around it, so just the text
RE: [Howto] Get Personalized status by RaceProUK on 07-01-2006 at 01:54 PM

quote:
Originally posted by J-Thread
/^(.*)(\xA0\{(.+)\})$/ig
Man, I really need to learn Regex! That makes no sense to me at all.

Edit: Actually, it does make sense to me. I think I may end up using that myself, but maybe with less parenthises :P like /^.*\xA0\{.+\}$/ig, which should also work.
RE: RE: [Howto] Get Personalized status by segosa on 07-01-2006 at 01:58 PM

quote:
Originally posted by RaceProUK
quote:
Originally posted by J-Thread
/^(.*)(\xA0\{(.+)\})$/ig
Man, I really need to learn Regex! That makes no sense to me at all.

Edit: Actually, it does make sense to me. I think I may end up using that myself, but maybe with less parenthises :P like /^.*\xA0\{.+\}$/ig, which should also work.


The brackets are needed, they group the stuff that's to be returned in the array (see first post).
RE: [Howto] Get Personalized status by RaceProUK on 07-01-2006 at 05:15 PM

Ah, I see.


RE: [Howto] Get Personalized status by L. Coyote on 07-01-2006 at 05:21 PM

quote:
Originally posted by J-Thread
/^(.*)(\xA0\{(.+)\})$/ig
omfg. I can't believe I didn't add "\xA0". I knew something was missing. :P

Thanks a lot, J-Thread. (Y) This is very useful.
RE: [Howto] Get Personalized status by mathieumg on 07-02-2006 at 05:39 AM

Haven't tested it, but there may be more than one { } pair, does it always take the last one?


RE: [Howto] Get Personalized status by J-Thread on 07-02-2006 at 10:49 AM

Yes, if you know some regular expressions, you can easily see that. The ^ stands for the beginning of the name, and the $ for the end. So to be able to find a match, there have to be a certain number (0 or more) characters (any characters you like) at the beginning of the string, then ASCII character 160 (\xA0), then a {, then 1 or more characters, then a } and that must be the end of the string. Exactly what you would do when you had to describe the process of finding the personal message in english.


RE: [Howto] Get Personalized status by ulyxes on 07-02-2006 at 11:40 AM

Sorry, I actually don't know Regex... Where do I have to attach this script? Thanks a lot for your help!


RE: [Howto] Get Personalized status by RaceProUK on 07-02-2006 at 02:09 PM

quote:
Originally posted by J-Thread
Yes, if you know some regular expressions, you can easily see that. The ^ stands for the beginning of the name, and the $ for the end. So to be able to find a match, there have to be a certain number (0 or more) characters (any characters you like) at the beginning of the string, then ASCII character 160 (\xA0), then a {, then 1 or more characters, then a } and that must be the end of the string. Exactly what you would do when you had to describe the process of finding the personal message in english.
That's still not a complete explanation: the * operator is greedy, and will match as many characters as possible. This way, no matter how many '\xA0{'s there are, .* will skip all but the last.
RE: RE: [Howto] Get Personalized status by segosa on 07-02-2006 at 03:52 PM

quote:
Originally posted by RaceProUK
quote:
Originally posted by J-Thread
Yes, if you know some regular expressions, you can easily see that. The ^ stands for the beginning of the name, and the $ for the end. So to be able to find a match, there have to be a certain number (0 or more) characters (any characters you like) at the beginning of the string, then ASCII character 160 (\xA0), then a {, then 1 or more characters, then a } and that must be the end of the string. Exactly what you would do when you had to describe the process of finding the personal message in english.
That's still not a complete explanation: the * operator is greedy, and will match as many characters as possible. This way, no matter how many '\xA0{'s there are, .* will skip all but the last.


How did you go from "Man, I really need to learn Regex! That makes no sense to me at all." to an expert? Were you sarcastic with your original post or are you just a quick learner?
RE: [Howto] Get Personalized status by RaceProUK on 07-03-2006 at 06:11 PM

quote:
Originally posted by segosa
How did you go from "Man, I really need to learn Regex! That makes no sense to me at all." to an expert? Were you sarcastic with your original post or are you just a quick learner?
The Regex confused me at first, but then I started to recall the little I'd learned, and managed to piece it together. Still, I'm no expert - I'm the first to admit it ;)