mIRC Homepage
Posted By: pouncer removing certain parts of a string - 23/09/07 05:43 PM
so for example if we take this

l[style co:#040404;b;]i[style co:#080808;b;]k[style co:#0C0C0C;b;]e [style co:#141414;b;]t[style co:#181818;b;]h[style co:#1C1C1C;b;]i[style co:#202020;b;]s [style co:#282828;b;]o[style co:#2C2C2C;b;]n[style co:#303030;b;]e [style co:#383838;b;]l[style co:#3C3C3C;b;]a[style co:#404040;b;]l[style co:#444444;b;]a[style co:#484848;b;]l[style co:#4C4C4C;b;]a[style co:#505050;b;]l[style co:#545454;b;]a[style co:#585858;b;]l

i want to remove the style tags and strip it down so it actually returns 'like this one lala..,,'
Posted By: hixxy Re: removing certain parts of a string - 23/09/07 05:52 PM
Code:
alias striptags { return $regsubex($$1,/\[ $iif($prop == strict,style \40) .+?\]/gx,) }


I've added a .strict property to make it only remove [style] tags. If you suppress .strict it will remove all tags, including [b], [i], etc..

To see the difference try this example:

Code:
alias test {
  var %tags = [b][i]l[style co:#040404;b;]i[style co:#080808;b;]k[style co:#0C0C0C;b;]e [style co:#141414;b;]t[style co:#181818;b;]h[style co:#1C1C1C;b;]i[style co:#202020;b;]s [style co:#282828;b;]o[style co:#2C2C2C;b;]n[style co:#303030;b;]e [style co:#383838;b;]l[style co:#3C3C3C;b;]a[style co:#404040;b;]l[style co:#444444;b;]a[style co:#484848;b;]l[style co:#4C4C4C;b;]a[style co:#505050;b;]l[style co:#545454;b;]a[style co:#585858;b;]l
  echo -a Strict: $striptags(%tags).strict 
  echo -a Normal: $striptags(%tags)
}
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 05:57 PM
works perfect thanks hixxy
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 06:28 PM
i found some problems because its only supposed to remove style tags for e.g

Code:
  var %tags = [[]root[][][[[]]

  echo -a Normal: $striptags(%tags)


Normal: root]

it should give [[]root[][][[[]] becasue there arent any style tags in it

sorry i should have been more clear in my first post. i only want to remove the style tags which look like
[style attributes]some text here[/style]
Posted By: hixxy Re: removing certain parts of a string - 23/09/07 06:30 PM
Read my bloody post.. I added a .strict property for that exact reason and I even explained it.
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 06:37 PM
ahh i see now, sorry.

and thanks again!
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 06:46 PM
another problem:

var %tags = :[style ff:Comic Sans MS;co:#4B0082;b;]hellooo[/style]

echo -a $striptags(%tags).strict gives me

:hellooo[/style]

any idea why it puts the extra [/style] on?
Posted By: hixxy Re: removing certain parts of a string - 23/09/07 06:51 PM
I told it to only remove [style ...] tags, this will work for those too:

Code:
alias striptags { return $regsubex($$1,/\[ $iif($prop == strict,(?:style \40|/style)) .*?\]/gx,) }
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 07:23 PM
thanks, im still getting some style echos though, for example

Code:
alias striptags { return $regsubex($$1,/\[ $iif($prop == strict,(?:style \40|/style)) .*?\]/gx,) }

alias test {
  var %tags = :[Style ff:Maiandra GD;co:#81CB41;b;](F)(¯`·.[style co:#ff0000;b;i;](L)(¯`·.(F)(r*)[style co:#4eee94;b;](\\\\_pony_1_//)(r*)[style co:#ff0000;b;i;](F).·´¯)(L)[style co:#7d26cd;b;i;].·´¯)(F)[/style]

  echo -a Strict: $striptags(%tags).strict
}


it echos

Strict: :[Style ff:Maiandra GD;co:#81CB41;b;](F)(¯`·.(L)(¯`·.(F)(r*)(\\\\_pony_1_//)(r*)(F).·´¯)(L).·´¯)(F)
Posted By: hixxy Re: removing certain parts of a string - 23/09/07 07:25 PM
Change /gx to /gix
Posted By: pouncer Re: removing certain parts of a string - 23/09/07 07:37 PM
thanks hixxy can i ask what the gix do?
Posted By: hixxy Re: removing certain parts of a string - 23/09/07 08:09 PM
/g = makes $regex() return the number of matches, rather than just 1 for a match and 0 for a nonmatch.

/i = case-insensitive, so /A/i would match even if you applied it to "aaa"

/x = ignore spaces in the expression, so /a a/x is equivalent to /aa/ .. I basically used it here because it's easier than using $+
© mIRC Discussion Forums