Skip to content
General IRCd

Need Help With Regex.

A TG007 community discussion started by Travis.

Discussion 14 posts
Page 1 of 1
Open
Topic #14926 · 14 published posts · 4,038 views

Hi, I haven't learned regex and I'm too busy to figure it all out right now. Can someone help me strip the font for the text events?

 

 

on $*:text:%st_filter_norm:#:{
on $*:text:%st_filter_cmd:#:{

on $*:text:/^\./gS:#:{


  %st_filter_cmd = $+(/^,$sts(cmd_prefix),/gS)
  %st_filter_norm = $+(/^[^\.^,$sts(cmd_prefix),]/gS)

$1 = ##*#Arial Black~#7F7F7F~1~1#*##Text

$2- = rest of text.

 

Thank you!

http://www.tg007.net/page/snippet&sid=28

Get information about ircWx here

Yeah but then you have to add the search parameter to it.

Can try something like this

 

; font $getstyle(1,$1-)
; color $getstyle(2,$1-)
; bold $getstyle(3,$1-)
; italic $getstyle(4,$1-)
alias getstyle {
  var %r $regex(STYLE,$2-,/^##\*#(.*)~#(.*)~(0|1)~(0|1)#\*##/gi)
  if ($1 == 1) return $regml(STYLE,1)
  if ($1 == 2) return $regml(STYLE,2)
  if ($1 == 3) return $regml(STYLE,3)
  if ($1 == 4) return $regml(STYLE,4)
}

i haven't been on chatcore in awhile but when i was I used

 

alias ccstrip { 
  if ($regex($1-,/##\*#(.*)~#(.*)~(.*)~(.*)#\*##/)) { var %ccol $regml(2) | var %cbold $regml(3) }
  return ($iif(%ccol != $null,$iif(%cbold == 1,)    $hex2mirccolor(%ccol)),$regsubex($1-, /^##\*.*\*##/,$null))
}

was something i threw together quickly back then

course i'm sure u know the hex2mirc alias from mirc forum

Edited Mar 7, 2011 11:12 PM by err0r

Get information about ircWx here

As far as all the trivia commands work, you would know them better than I would. I revamped this to work for IRC users without fonts as well. Tested and functional, you just have to adapt to whatever trivia does. I am guessing it should be in all the on text commands.

 

on $*:TEXT:/^(##\*.*\*##)?(.*)/:#: {
  msg # $1- ... ORIGINAL
  tokenize 32 $iif($regml(2), $v1, $regml(1))
  msg # $1- ... STRIPPED
}

Good luck

Stupidity is a metric of success.

Thanks Pablo. That's working for me. What I'm wondering about now is this regex.

 

/^[^\.^-]/gS

 

 

What does it do?

Thanks Pablo. That's working for me. What I'm wondering about now is this regex.

 

/^[^\.^-]/gS

 

 

What does it do?

 

 

Well from what I can tell (which isn't much with regex):

 

^ matches the beginning character

[^ negates the group.. matches anything not in the []

\. period character (negated)

^- also dash character (negated)

g reads the expression greedy / repeat

S reads the expression ignoring spaces

 

From testing I concluded it matches any string that does not begin with a . or - (and a few other characters $%^ .. no clue why). I also do not see the point in the g or S being that we are only matching the beginning of a string.

 

The regex pattern seems to match anything that is not a - or . command, or just regular alphanumeric responses.

 

To go about the adapting this to CC's font codes, I am at a loss of words ATM at 4 am. Everything I try is not really working. I just know the equivalent in non-regex coding would be: (after it is stripped)

 

if ($left($1,1) !isin -.) { commands.. }

Someone could probably make it work, but now my head just hurts lol.. Maybe doing a regsubex to remove the font code is the answer to then process the text.

Stupidity is a metric of success.

Oh cool thanks, that makes a lot of sense now. So I want to strip out the font code and make sure it doesn't match ^. or ^-. Could I do something like:

 

/^##\*.*\*##[^\.^-]/gS

Edited Apr 13, 2011 1:06 PM by Travis

/^[^\.^-]/gS

 

 

What does it do?

 

It will match one character to exclude the "-" symbol and disregard the rest from the start of a string. The /g modifier means to match more than one match respectively. The /S is to strip control codes, mainly work for mIRC and not a standard regex modifier.
Edited Apr 13, 2011 5:09 PM by Fanfare

Oh cool thanks, that makes a lot of sense now. So I want to strip out the font code and make sure it doesn't match ^. or ^-. Could I do something like:

 

/^##\*.*\*##[^\.^-]/gS

 

You can use regex's negative look ahead:

/(?!\.|\^|-)##\*.*\*##/
If you mean that you want to ignore both the symbol "^." and "^-." This pattern should do the trick. The dot and the caret symbol are to be escaped because they have special meanings in regex.
Edited Apr 13, 2011 5:44 PM by Fanfare

My bad. I didn't test the regex pattern earlier. I think the edit should work.

Thanks for your help, I will try it out.

Alright I tried it but the expressions are $true for any text.

 

What I'm trying to do is convert Supertrivia for chatcore network. Supertrivia has 3 text events and I don't want to take the time to combine them into one text event. I'd like to just make this work how it is.

 

The problem is each text event uses regex to look at the first character of incoming text but this network has a font code for $1. So I need to look at the first character after the font code.

 

The first text event is supposed to check for text that starts with a . only.

on $*:text:/^(##\*.*\*##)?(.*)/:#:{ }


The second text event is supposed to check for text starting with ! only.

on $*:text:%st_filter_cmd:#:{ }

%st_filter_cmd = /^(##\*.*\*##)?(!*)/gS


The last text event checks for all text that doesn't start with a . or a !.

on $*:text:%st_filter_norm:#:{ }

%st_filter_norm = /(?!\.|\^|!)##\*.*\*##/gS

Can anyone please help me with the proper regex to do these things? Thank you.