Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; $wc2re(<wildcard text>).cs
- ; -Converts <wildcard text> to a regex pattern
- ; -if .cs is specified, the match is case sensative
- ;
- ; How to do it:
- ;declare the alias
- alias wc2re {
- ;setup variable to be used when formatting
- var %subbed
- ;removing any repeats of * ie: "***" becomes "*"
- var %subbed = $regsubex($1-,/\*+/g,*)
- ;Using $regsubex(), replace all "special" regex characters in %subbed with their escaped values.
- ;Special characters being: |[]{}()\/.
- %subbed = $regsubex(%subbed,/([|\[\]{}()\\\/.])/g,\\t)
- ;After subbing the regex special characters, replace ?'s with .'s and *'s with .*'s
- %subbed = $replace(%subbed,?,.,*,.*)
- ;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
- %subbed = /^ $+ %subbed $+ $ $+ /
- ;Check to see if the $prop was "cs" and if not tack "i" onto the end of the pattern to make it case insensative
- if ($prop != cs) { %subbed = %subbed $+ i }
- ;now return the result
- return %subbed
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement