|
FuSoYa Novice
Joined: 10 Feb 2007 Posts: 34 Location: Denton, TX
|
Posted: Sun Apr 20, 2008 4:31 am
Coloring random variables. |
If there is something I want to be captured and colored such as [NES Quit]
How do I make it color ONLY the items within the brackets and not the brackets?
Thanks.
Brandon |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sun Apr 20, 2008 12:08 pm |
You need to use #pcol and set up a back reference in your pattern (i.e. use parentheses) and then use %x1 (or whatever number suits your backreference) to tell it where to colour. Remember that square brackets are usually special characters, so you'll need to escape them, too.. something like this:
~[(NES Quit)~]
#pcol green %x1 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Apr 20, 2008 12:18 pm |
There're a number of methods, mostly dependent on how confident you are with regexes. The simplest way would probably be to use #sub and MXP:
#trig {~[(*)~]} {#sub {%concat("[<color whatevercolournameiwanttouse>",%1,"</color>]")}
A more complex way would be to use positive lookbehind and lookahead in a regex so that the brackets must be there, but don't form part of the match. If you don't know what I'm talking about, it's probably past your abilities. If you're looking to learn, try this site, which'll teach you all about regex syntax. Lookahead and lookbehind will likely be in the advanced section. |
|
|
|
FuSoYa Novice
Joined: 10 Feb 2007 Posts: 34 Location: Denton, TX
|
Posted: Sun Apr 20, 2008 2:31 pm |
#trig {~[(*)~]} {#sub {%concat("[<color white>",%1,"</color>]")}
When I tried this one it told me error parsing command illegal token? What did I do wrong? |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sun Apr 20, 2008 2:35 pm |
You're missing a closing brace
it should be
Code: |
#trig {~[(*)~]} {#sub {%concat("<color white>",%1,"</color>")} } |
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
FuSoYa Novice
Joined: 10 Feb 2007 Posts: 34 Location: Denton, TX
|
Posted: Mon Apr 21, 2008 5:22 am |
Ok I got it to work but now how do I get it to keep the brackets that are already there in the same dull green color?
Brandon |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Apr 21, 2008 5:41 am |
Put them at the ends of the string, outside the colour tag:
#trig {~[(*)~]} {#sub {%concat("[<color white>",%1,"</color>]")} }
You can always put colour tags around each of them to colour them properly if that removes the colours, too. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Mon Apr 21, 2008 5:42 am |
The one Dharkael posted forgot to put in the [ ] in the #sub.
Should be:
Code: |
#sub {%concat("[<color white>",%1,"</color>]")} |
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Mon Apr 21, 2008 11:27 am |
Can someone explain why you would prefer sub to pcol (assuming that really all you want to do is colour and capture)? Sorry if I'm being dense, it just seems like extra work.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Apr 21, 2008 12:29 pm |
PCOL keeps colour codes, SUB removes them. You can just put whem into the string you sub, though, so it's not that big a deal.
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Mon Apr 21, 2008 1:46 pm |
OK, so if you wanted to make the brackets a different colour, too, you would need sub, but why use it in this case (instead of pcol)? Still confused here.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Apr 21, 2008 3:06 pm |
Okay, I was confused - when I said PCOL in the post above, I meant PSUB. You could use PCOL here, actually, and it should work fine.
|
|
|
|
|
|