mIRC Homepage
Posted By: Ledah Need help from Regex savvy people - 31/07/09 07:40 PM
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)
Posted By: argv0 Re: Need help from Regex savvy people - 31/07/09 10:36 PM
You can just add the space to the character classes youre matching for:

Code:
[A-ZÀÁÂÃÄÅÆÇÈÉÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ ]+

Posted By: Ledah Re: Need help from Regex savvy people - 31/07/09 11:31 PM
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.
Posted By: argv0 Re: Need help from Regex savvy people - 31/07/09 11:59 PM
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.
Posted By: Ledah Re: Need help from Regex savvy people - 01/08/09 05:10 PM
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
© mIRC Discussion Forums