Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 1.20 KB | None | 0 0
  1. ;
  2. ;   $wc2re(<wildcard text>).cs
  3. ;     -Converts <wildcard text> to a regex pattern
  4. ;     -if .cs is specified, the match is case sensative
  5. ;
  6. ; How to do it:
  7.  
  8. ;declare the alias
  9. alias wc2re {
  10.  
  11.   ;setup variable to be used when formatting
  12.   var %subbed
  13.  
  14.   ;removing any repeats of * ie: "***" becomes "*"
  15.   var %subbed = $regsubex($1-,/\*+/g,*)
  16.  
  17.   ;Using $regsubex(), replace all "special" regex characters in %subbed with their escaped values.
  18.   ;Special characters being: |[]{}()\/.+
  19.   %subbed = $regsubex(%subbed,/([\Q|[]{}()\/.+\E])/g,\\t)
  20.  
  21.   ;After subbing the regex special characters, replace ?'s with .'s and *'s with .*'s
  22.   %subbed = $replace(%subbed,?,.,*,.*)
  23.  
  24.   ;You need to replace "&" if it is followed by space, or end of line
  25.   %subbed = $regsubex(%subbed,/&(?= |$)/g,[^ ]+\b)
  26.  
  27.   ;Once we have everything substituted, we need to wrap the pattern with /^$/s so the pattern will try to match the whole string, instead of just parts of it
  28.   %subbed = /^ $+ %subbed $+ $ $+ /s
  29.  
  30.   ;Check to see if the $prop was "cs" and if not tack "i" onto the end of the pattern to make it case insensative
  31.   if ($prop != cs) { %subbed = %subbed $+ i }
  32.  
  33.   ;now return the result
  34.   return %subbed
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement