[Howto] Get Personalized status |
Author: |
Message: |
J-Thread
Full Member
Posts: 467 Reputation: 8
– / / –
Joined: Jul 2004
|
O.P. [Howto] Get Personalized status
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
|
|
07-01-2006 12:44 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: [Howto] Get Personalized status
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 like /^.*\xA0\{.+\}$/ig, which should also work.
This post was edited on 07-01-2006 at 01:56 PM by RaceProUK.
|
|
07-01-2006 01:54 PM |
|
|
segosa
Community's Choice
Posts: 1407 Reputation: 92
Joined: Feb 2003
|
RE: RE: [Howto] Get Personalized status
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 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).
The previous sentence is false. The following sentence is true.
|
|
07-01-2006 01:58 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: [Howto] Get Personalized status
Ah, I see.
|
|
07-01-2006 05:15 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
RE: [Howto] Get Personalized status
quote: Originally posted by J-Thread
/^(.*)(\xA0\{(.+)\})$/ig
omfg. I can't believe I didn't add "\xA0". I knew something was missing.
Thanks a lot, J-Thread. This is very useful.
Hack, hack, hack!
Finally became a Systems Analyst!
|
|
07-01-2006 05:21 PM |
|
|
mathieumg
Full Member
Posts: 181 Reputation: 2
35 / /
Joined: May 2004
|
RE: [Howto] Get Personalized status
Haven't tested it, but there may be more than one { } pair, does it always take the last one?
Official MessengerPlus! Live French Translator
Official StuffPlug 3 French Translator
|
|
07-02-2006 05:39 AM |
|
|
J-Thread
Full Member
Posts: 467 Reputation: 8
– / / –
Joined: Jul 2004
|
O.P. RE: [Howto] Get Personalized status
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.
|
|
07-02-2006 10:49 AM |
|
|
ulyxes
Junior Member
Posts: 21
36 / / –
Joined: Jun 2006
|
RE: [Howto] Get Personalized status
Sorry, I actually don't know Regex... Where do I have to attach this script? Thanks a lot for your help!
|
|
07-02-2006 11:40 AM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: [Howto] Get Personalized status
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.
|
|
07-02-2006 02:09 PM |
|
|
segosa
Community's Choice
Posts: 1407 Reputation: 92
Joined: Feb 2003
|
RE: RE: [Howto] Get Personalized status
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?
The previous sentence is false. The following sentence is true.
|
|
07-02-2006 03:52 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|