mIRC Home    About    Download    Register    News    Help

Print Thread
Regular Expresion help.. #68208 16/01/04 08:25 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Ex. i have a word "acceleration" and i whant to check if all leters from other word "relation" is in that word ?

$regex(Catch,acceleration,/???relation???/) must return 1
$regex(Catch,acceleration,/???rellation???/) must return 0

Thank You.


mIRC Chm Help 6.16.0.3 Full Anchored!
Re: Regular Expresion help.. #68209 16/01/04 10:06 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
/help $pos


-KingTomato
Re: Regular Expresion help.. #68210 17/01/04 02:28 AM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
How about a simple loop instead?
  • var %a = relation,%b = acceleration,%i = 1
    while $mid(%a,%i,1) isin %b { inc %i }
    echo -a $iif(%i > $len(%a),All present!,Missing chars.)

Re: Regular Expresion help.. #68211 17/01/04 03:11 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Yap, i know about that function ;P But i whant to solve my problem in a nice way.. With a Regular Expresion wink I'm asking if that is posible.. And if that is posible.. How ?


mIRC Chm Help 6.16.0.3 Full Anchored!
Re: Regular Expresion help.. #68212 17/01/04 03:29 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Thank you for you cool solution, i still whant Regual Expresion equivalent wink
If nobody know or a Regual Expresion just can't do that.. I will use you solution..


mIRC Chm Help 6.16.0.3 Full Anchored!
Re: Regular Expresion help.. #68213 17/01/04 05:21 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
AFAIK a regular expression couldn't do what you want.

If you want there to be the correct number of letters present, you'll want to use $count() in an alias like this:
Quote:
contains {
var %haystack = $1, %needle = $2
while $left(%needle, 1) {
var %char = $ifmatch
var %c = $count(%needle, %char)
if (%c > $count(%haystack, %char)) return
var %needle = $remove(%needle, %char)
}
return $true
}


eg.
$contains(acceleration, relation) is true
but $contains(one, none) is not true because one doesn't have two n's.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Regular Expresion help.. #68214 17/01/04 06:19 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Thank you a lot ! You script works like i whant.. And very fast(1000 in 0.903s(cpu 333Mhz)) !
Now i will torture you script with 3 millions words wink


mIRC Chm Help 6.16.0.3 Full Anchored!
Re: Regular Expresion help.. #68215 17/01/04 11:21 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Glad it works well for you, but after you mentioned it's speed you brought out the obsessive side of me and I decided to optimize it a bit.

Code:
contains {
  ; $contains(haystack, needle)
  var %needle = $2, %count
  while $left(%needle, 1) {
    %char = $ifmatch
    if ($count(%needle, %char) > $count($1, %char)) return
    %needle = $remove(%needle, %char)
  }
  return $true
}


That worked approx. 25% faster for me. The code is a bit harder to read so I added a small comment to help remind people of the parameters.

And I even used the correct [[i][/i]code] tags around it this time!


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Regular Expresion help.. #68216 18/01/04 01:43 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Ugh, I'm an idiot. /var declaration is wrong in that last one.

Code:
contains {
  ; $contains(<haystack>, <needle>)
  var %needle = $2, %char
  while $left(%needle, 1) {
    %char = $ifmatch
    if ($count(%needle, %char) > $count($1, %char)) return
    %needle = $remove(%needle, %char)
  }
  return $true
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Regular Expresion help.. #68217 18/01/04 07:06 PM
Joined: Apr 2003
Posts: 414
Adrenalin Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 414
Thank you again.. You script realy help me a lot..
Also to make you script work with numbers(ex. with 0) "while $left(%needle, 1) {" must be "while $left(%needle, 1) != $null {".
Thanks for you time.


mIRC Chm Help 6.16.0.3 Full Anchored!