$_iswm

By Sigh_ on Nov 12, 2004

; $_iswm by Sigh

; Lets you escape characters when performing a wildmatch

; Usage: $_iswm(string,match1,match2,...,matchN)

; Returns $true if any of the matches given is a wildmatch of the string

; Characters are escaped with a backslash character \

; For example, to check if "ab" exists anywhere in $1- you could use if ($_iswm($1-,*a*b))

alias _iswm { 
  var %i = 2,%m 
  while (* iswm $($ $+ %i,2)) { 
    .echo -q $regsub(a,$replacecs($v2,\\,\\E\\134\\Q) ,/(?<!\\)(?:(\*)|\?)/g,\\\\E.\1\\\\Q,%m) $& 
      $regsub(%m,/(?<=^| )&(?= |$)/g,\\\\E[^ ]+\\\\Q,%m) $regsub(%m,/(?<!\\)\\/g,,%m) 
    if ($regex($1,$+(/^\Q,%m,\E$/s,$iif($prop != cs,i)))) return $true 
    inc %i 
  } 
  return $false 
}

Comments

Sign in to comment.
LIQUID_NiTrO   -  Nov 12, 2004

Dayum. Nice job.

 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.