Advertisement
Guest User

Untitled

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