|
|
|
Joined: Mar 2005
Posts: 39
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2005
Posts: 39 |
Hello, i was wondering if there's an shorter code to check for 4 or more repeating characters? This way works, but its very long if u gonna use the whole alphabet.. if ($count($1-,aaaa,bbbb,pppp,etc)
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
var %a = a b c d e f g h i j k l m n o p q r s t u v w x y z
while %a {
if $str($gettok(%a,1,32),4) isin $1- {
echo -a $gettok(%a,1,32)
}
var %a = $remtok(%a,$gettok(%a,1,32),1,32)
}
Not knowing exactly why you're searching for 4 character repeats, the above code might work...might not be shorter than how you were doing it, but ....
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
if($regex(aaaabbbb,/(\w{4})/g)) { do something }
$v1 will hold how many repetitions there have been found, so in this example 2, with $regml(N) you can get the Nth repition in order of apearance so in this case $regml(1) is aaaa $regml(2) is bbbb
might not be exactly what you want as this returns true for letter, number or an underscore being repeated 4 times
in case you only want letters use if($regex(aaaabbbb,/([a-z]{4})/gi)) { do something }
Last edited by Mpdreamz; 12/12/05 10:50 AM.
$maybe
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
This won't work. \w{4} matches ANY 4 <letter/number/_> characters, not the same ones. You'd need
var %r = /(\w)\1{3,}/g | if ($regex($1-,%r)) { do stuff }
in both cases, $regml(N) returns the Nth repeating letter (it can be modified to catch the actual string of repeating letters too)
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
doh ! cant believe i missed that :tongue:
$maybe
|
|
|
|
|
|
|
|