|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
OP
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.
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
-KingTomato
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
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.)
|
|
|
|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
OP
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 I'm asking if that is posible.. And if that is posible.. How ?
|
|
|
|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2003
Posts: 414 |
Thank you for you cool solution, i still whant Regual Expresion equivalent If nobody know or a Regual Expresion just can't do that.. I will use you solution..
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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: 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.
|
|
|
|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
OP
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
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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. 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.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
Ugh, I'm an idiot. /var declaration is wrong in that last one. 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.
|
|
|
|
Joined: Apr 2003
Posts: 414
Fjord artisan
|
OP
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.
|
|
|
|
|