|
Joined: Dec 2002
Posts: 68
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 68 |
I have text like this: [1;34mYou see exits leading [0;37m[1;34mnortheast, south, and northwest. I need to detect all the ANSI codes (they all look like [1;34m or similar), and then return the whole phrase in mIRC codes (using the identifier $ansi2mirc). Where there is a different ANSI code, it needs to find the new color for when it changes, so there could be several different ANSI codes in a sentence, meaning that there would be several different colors. It has to find all of them. Thanks. Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility.
|
|
|
|
Joined: Mar 2003
Posts: 1,271
Hoopy frood
|
Hoopy frood
Joined: Mar 2003
Posts: 1,271 |
ok, I'm not the world's best with regular expressions, but set your whole line in a variable called %txt and apply the following line to count how many times they format [N;NNm makes an appearance.
$regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
The problem is $ansi2mirc([1;34m) returns [1;34m for mem, so I'm probably doing something wrong in detecting the ansi code. You can use this as a basis for a $regsub, to replace the ansi code with $ansi2mirc(ansicode)
DALnet #Helpdesk I hear and I forget. I see and I remember. I do and I understand. -Confucius
|
|
|
|
Joined: Dec 2002
Posts: 68
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 68 |
You need a $chr(27) before the [#;##m. You might need to change your code, I'm not sure.
|
|
|
|
Joined: Mar 2003
Posts: 1,271
Hoopy frood
|
Hoopy frood
Joined: Mar 2003
Posts: 1,271 |
Ok, this is not the most beautiful, and a $regsub will probably be faster, but this works: set your line into a variable called %txt
alias tst {
var %i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
while (%i >= 1) {
%txt = $replace(%txt,$regml(1),$ansi2mirc($regml(1)))
%i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
}
echo -a %txt
}
DALnet #Helpdesk I hear and I forget. I see and I remember. I do and I understand. -Confucius
|
|
|
|
Joined: Dec 2002
Posts: 68
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 68 |
I totally forgot to point this out, sometimes the ";" is not there. Example: [36mThe bright sun shines down, blanketing you with its life-giving warmth. [37m[36mA runic If somebody could fix the code above, that would be awesome. Thanks.
|
|
|
|
Joined: Mar 2003
Posts: 1,271
Hoopy frood
|
Hoopy frood
Joined: Mar 2003
Posts: 1,271 |
replace the regex with
$regex(%txt,/(\[[0-9]?;?[0-9]{2}m)/g)
or so I'm told
DALnet #Helpdesk I hear and I forget. I see and I remember. I do and I understand. -Confucius
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility. I'll take a guess here but try this: //var %a = [1;34mYou see exits leading [0;37m[1;34mnortheast, south, and northwest. | echo -a $ansi2mirc(%a) The reason that it errors could be the commas in the string. Commas are used for separating parameters in identifiers: if put directly in $ansi2mirc() mirc thinks you're passing more than one parameters to it, so it errors.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Mar 2003
Posts: 1,271
Hoopy frood
|
Hoopy frood
Joined: Mar 2003
Posts: 1,271 |
Which is why I suggested he put the string in a variable and use the variable in the #regex...
DALnet #Helpdesk I hear and I forget. I see and I remember. I do and I understand. -Confucius
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
If you agree that the commas was the cause of the error, why did you post the regex solution? What I'm saying is that it's possible that $ansi2mirc only returned an error because of the commas in the string, not because it doesn't support more than one codes in the input. $ansi2mirc does support multiple codes (compare the outputs of $ansi2mirc(%txt) and /tst, you'll see they're the same), which means that the regex isn't needed.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Mar 2003
Posts: 1,271
Hoopy frood
|
Hoopy frood
Joined: Mar 2003
Posts: 1,271 |
I said the regex coukldn't deal with comma's in the string =which is true=. I did not say that $ansi2mirc(string) wouldn't work, the original poster did (see original post, bottom line). I never said commas were the problem in $ansi2mirc (but they will be - mirc identifiers cannot deal with comma's in text strings since comma's are used to separate arguments), when I said comma's would give a problem, I was referring to the regex.
DALnet #Helpdesk I hear and I forget. I see and I remember. I do and I understand. -Confucius
|
|
|
|
|