mIRC Home    About    Download    Register    News    Help

Print Thread
#173104 20/03/07 08:19 PM
C
CitizenKane
CitizenKane
C
I use scripts to rewrite the displayed text for all of the events. However, if someone uses the [ctrl-K] char in the text to return the text to the default color, that messes up my scheme, because the color turns to black instead of whatever color I've matched with the event.

The [ctrl-O] character can be dealt with with a simple $replace, but for this, I was trying to set up a $regsub that would match any color-code not followed by 0-9 and replace the [ctrl-K] char with a %color variable...

#173106 20/03/07 08:47 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Maybe this will help.
Code:
alias cc var %a | return $null($regsub($1,/(?<=\x03)\D/g,$+(%,color),%a)) %a

if doesn't then post some examples of what you need exactly.

#173108 20/03/07 09:04 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
The following should work. I've used %text as the input, obviously you'll need to change that to $1- or your variable name. This will also replace [Ctrl+K]99 which is a special colour code that's equivalent to [Ctrl+K] without a number.

Code:
$regsubex(%text, /\x0399|\x03(?=\D)/g, $+($chr(3),%color))

C
CitizenKane
CitizenKane
C
Fascinating. The (?=\D) part throws me for a little loop, but feh. Seems to work fine, so thanks. smile

#173206 22/03/07 03:48 AM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
If you're wondering what the (?=\D) is doing:

\D just represents any non-digit character (opposite of \d).

The (?=...) is a lookahead assertion. Essentially the \x03(?=\D) is the same as \x03\D except the lookahead assertion means that although the expression only matches a [Ctrl+K] followed by a non-digit, the part in the lookahead assertion is not consumed - that is, it's not considered part of the match (ie. not part of what's replaced by $regsubex) and if there was any more to the regular expression after the lookahead assertion it would continue matching from immediately before the non-digit character instead of immediately after it.

Not sure if that helps or not. As with all things involving regular expressions it's simple when you know what's happening but damn near impossible to explain to someone who doesn't.

C
CitizenKane
CitizenKane
C
Helps a bunch. I completely understand your expression now. I never considered the possibility of lookarounds. I looked it up, and now I know how to do lookbehinds, too. I learned something new. smile

#173344 24/03/07 12:01 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Lookarounds doesn't consume chars. also the lookbehind is zero-width that means no +?*.

Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
You probably mean lookbehinds must have fixed-width, although alternatives with different (fixed) width are permitted, eg (?<=ab|abc) is fine but (?<=abc?) is not.

Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
That's what I meant at the first time. thanks


Link Copied to Clipboard