mIRC Home    About    Download    Register    News    Help

Print Thread
Need help from Regex savvy people #214375 31/07/09 07:40 PM
Joined: Oct 2006
Posts: 6
L
Ledah Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Oct 2006
Posts: 6
So i'm trying to make an alias in regex that basically changes all numbers to a color, all lowercase to another color, all uppercase ot another and all ascii to a fourth color.

Code:
alias Themed { 
  var %thm
  %x = $regsub($strip($1-),/([0-9]+)/g,$+($tc(3),\1),%thm)
  %x = $regsub(%thm,/([A-Z]+)/g,$+($tc(1),,\1,),%thm)
  %x = $regsub(%thm,/([\\\]\-\^!"#$%,&'()*+.
/:;<=>?@[_`{|}~
]+)/g,$+($tc(4),\1),%thm)
  %x = $regsub(%thm,/([a-z]+)/g,$+($tc(2),\1),%thm)
  return %thm 
}


(Sorry if its a little messy, it turns out a few ascii characters are turning into others x_x. basically the upper case ascii character that are letters with accents ( and such) are considered "Upper" or "Lower" instead of "Ascii", Also i've put the ascii part in three lines just so it doesnt stretch the page, but it's all in one normally.
This is what i have, and so far it works nicely, but there is a little thing that bugs me in it. The Space character (or any invisible characters for that matter) dont count as a character and thus make the script have to re-add a new, totally uneeded color code. ($tc(N) is my "Get the Color code identifier)

Turns for example: HEY into 04HEY, or Hi into 04H14i. But when spaces are involved such as Hey there, it would go 04H14ey 14there. Totally uneeded secondary 14 in there. In more-or-less long messages, that tends to stretch the message length too much.

So, i'm wondering is anyone with more knowledge in Regex could help me actually make spaces "clones" the "type" of the character before it as well as other invisible character so they do not create double unecessary control codes. (and/or clean it up, especially the ascii part)

Re: Need help from Regex savvy people [Re: Ledah] #214380 31/07/09 10:36 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
You can just add the space to the character classes youre matching for:

Code:
[A-Z ]+



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Need help from Regex savvy people [Re: argv0] #214384 31/07/09 11:31 PM
Joined: Oct 2006
Posts: 6
L
Ledah Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Oct 2006
Posts: 6
I tried that, by adding the space to all four (Since, i need it in all four, depending on what's the previous character)

The result was... scary. It basically added all four colors for every space there was, along with not fixing the original problem (except that now, due to the four codes before it, it was somewhat needed)

Result: Five time as many uneeded codes, that's why i would need some fancy regex to make it all works frown

My other option would be to simply make an alias that scan every character of given text and color it if it needs to, or do nothing if it's the same kind as the previous. The problem with that solution would be that it requires much more output from mirc compared to regex. And i would like to avoid that.

Re: Need help from Regex savvy people [Re: Ledah] #214387 31/07/09 11:59 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
alias Themed { 
  var %thm 
  %thm = $regsubex($strip($1-),/([0-9][0-9 ]*)/g,$+($tc(3),\1))
  %thm = $regsubex(%thm,/([A-Z][A-Z ]*)/g,$+($tc(1),,\1,))
  %thm = $regsubex(%thm,/([a-z][a-z ]*)/g,$+($tc(2),\1))
  return %thm 
}


I removed that middle line of symbols for simplicity in writing, you can add it back in. There might be a way to write those regexes more concisely with some extra trickery.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Need help from Regex savvy people [Re: argv0] #214396 01/08/09 05:10 PM
Joined: Oct 2006
Posts: 6
L
Ledah Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Oct 2006
Posts: 6
Quote:
I removed that middle line of symbols for simplicity in writing, you can add it back in. There might be a way to write those regexes more concisely with some extra trickery.


Thanks, that's working great so far laugh