TheImrac commented on a Page, $charcheck  -  Nov 01, 2008

Lindrian I would love to know how or why that regex is "so wrong in so many ways".

Edit: BTW the regex is much more efficient then using a while loop.

alias charcheck { var %c $chr($2) | return $regsubex($1,/(?<= |^)([^ $+ %c $+ ][^ ]*)(?= |$)/g,%c $+ \1) }

alias charcheck1 {
  var %t 1
  while (%t <= $numtok($1,32)) {
    var %front, %frontend = $instok(%frontend,$iif($left($gettok($1,%t,32),1) != $chr($2),$+($chr($2),$gettok($1,%t,32)),$gettok($1,%t,32)),0,32)
    inc %t
  }
  return %frontend
}

alias ctest {
  var %t = $ticks, %x = 100
  while (%x) {
    noop $charcheck(tehis #is a #test asd asd a #as asd # asd # asd ## a as a a aa sd a asd a asd a asd as asd asd asd asd asd as asd as dasd asd asdasd # asd a # asd # asda a # asd #asd as #a #asd #asda #reasa #adsaa #asd #asdae as asd a sdas asd as asd asd asd ad  ,35)
    dec %x
  }
  echo -b Regex Time: $calc($ticks - %t)
  var %t = $ticks, %x = 100

  while (%x) {
    noop $charcheck1(tehis #is a #test asd asd a #as asd # asd # asd ## a as a a aa sd a asd a asd a asd as asd asd asd asd asd as asd as dasd asd asdasd # asd a # asd # asda a # asd #asd as #a #asd #asda #reasa #adsaa #asd #asdae as asd a sdas asd as asd asd asd ad  ,35)
    dec %x
  }
  echo -b WhileLoop Time: $calc($ticks - %t)
}

just do /ctest

My average regex time was between 65-85 ms, while the while loop was between 700 and 800ms.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.