|
|
Joined: Mar 2006
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2006
Posts: 47 |
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...
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
Maybe this will help.
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.
Kind Regards, blink
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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. $regsubex(%text, /\x0399|\x03(?=\D)/g, $+($chr(3),%color))
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Mar 2006
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2006
Posts: 47 |
Fascinating. The (?=\D) part throws me for a little loop, but feh. Seems to work fine, so thanks. 
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
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.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Mar 2006
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2006
Posts: 47 |
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. 
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
Lookarounds doesn't consume chars. also the lookbehind is zero-width that means no +?*.
Kind Regards, blink
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
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.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
That's what I meant at the first time. thanks
Kind Regards, blink
|
|
|
|
|
|