Jump to content

Need Help With Regex.


Guest Travis

Recommended Posts

Guest Travis

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!

Link to comment
Share on other sites

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)
}
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

Guest Travis

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 by Travis
Link to comment
Share on other sites

/^[^\.^-]/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 by Fanfare
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...