mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Sephiroth_
IT WAS AN EXAMPLE, goddamn... xD


Examples are fine. When they are valid. The point is that $replace() cannot do everything that $replacex() does without potential inaccuracies. So your statement that $replacex() was not needed is false and that needs to be clear both for you and anyone reading this.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
i would also like to see W and R options that behave as they do with $hfind() :P

also, here's a small snippet i had lying around that accurately generates a regular expression (which isn't always efficient!) from a wildmatch:

Code:
alias wmcs2re return $+(/(*UTF8)^\Q, $regsubex($replacecs($1, \E, \E\\E\Q, *, \E.*\Q, ?, \E.\Q), /&(?= |$)/g, \E[^ ]+\Q), \E$/s)


$wmcs2re(a ? b & *c*) = /(*UTF8)^\Qa \E.\Q b \E[^ ]+\Q \E.*\Qc\E.*\Q\E$/s

hopefully it covers all bases. argv's method of escaping meta-characters generally yields shorter and more readable expressions, but i probably made it the above way to avoid having to list them all ;D


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Here's mine though a little more complicated
Code:
$Wc2Re(wildcard text) -> Converts a wildcard matching pattern to a regular expressions
$Wc2Re(wildcard text).cs -> THe return regular expression is case sensitive

alias Wc2Re return $+(/(*UTF8)^,$regsubex($1-,/([\Q$^|[]{}()\/.+\E])|(&(?= |$))|([?*]+)/g,$Wc2Re:Rep(\t)),$,/s,$iif($prop != cs,i))

alias -l Wc2Re:Rep {
  if ($1 == &) return \S+\b
  if (* !isin $1 && ? !isin $1) return \ $+ $1
  if (? !isin $1) return .* 
  if ($count($1,?) < 5) return $str(.,$v1) $+ $iif(* isin $1,+)
  return $+(.,$chr(123),$count($1,?),$iif(* isin $1,$chr(44)),$chr(125))
}

$wc2re(a* t?est o? w?*?s has occ?????????) = /(*UTF8)^a.* t.est o. w..+s has occ.{9}$/si

edited to shorten code, and fix typing errors

Last edited by FroggieDaFrog; 19/01/11 01:23 PM.

I am SReject
My Stuff
Page 2 of 2 1 2

Link Copied to Clipboard