mashiina Posted June 4, 2012 Report Share Posted June 4, 2012 (edited) Sveiki. Vai varētu kāds palīdzēt vai padalīties ar preg_match`u: 1) qwerty- valīds; 2) qwerrrty- nav valīds; Respektīvi, ja trīs vienādi simboli pēc kārtas, tad nav valīds. Edited June 4, 2012 by mashiina Quote Link to comment Share on other sites More sharing options...
WHOAMi Posted June 4, 2012 Report Share Posted June 4, 2012 (edited) <?php // Rinda kas var vai nevar saturet qwerty $string = "qwerty"; // Satur rindu if (preg_match("/\bqwerty\b/i", $string)) { echo "valid."; } else { echo "not valid."; } // Rinda kas var vai nevar saturet qwerty $string = "qwerrrrty"; // Nesatur rindu if (preg_match("/\bqwerty\b/i", $string)) { echo "valid"; } else { echo "not valid"; } ?> Ja gribi, lai pārbauda vai atkārtojas kāds konkrēts simbols, tad nomaini: preg_match("/\bqwerty\b/i", $string) uz preg_match("/qwe(r){1,3}ty/",$string); Edited June 4, 2012 by WHOAMi Quote Link to comment Share on other sites More sharing options...
briedis Posted June 4, 2012 Report Share Posted June 4, 2012 WHOAMi, qwerty bija domāts tikai kā paraugs, man liekas, vajadzētu spēt validēt jebkuru vārdu... Es, godīgi sakot, uz sitiena nevaru iztēloties reg izteiksmi, kas to spētu :) Quote Link to comment Share on other sites More sharing options...
WHOAMi Posted June 4, 2012 Report Share Posted June 4, 2012 (edited) WHOAMi, qwerty bija domāts tikai kā paraugs, man liekas, vajadzētu spēt validēt jebkuru vārdu... Es, godīgi sakot, uz sitiena nevaru iztēloties reg izteiksmi, kas to spētu :) jā, es sapratu, bet cik es skatījos un pat paguglēju, kaut ko tik specifisku var izdarīt uzkodējot atsevišķu moduli, kurš filtrēs katru vārdu, tāpēc pievienoju potenciālo variantu. Edited June 4, 2012 by WHOAMi Quote Link to comment Share on other sites More sharing options...
briedis Posted June 5, 2012 Report Share Posted June 5, 2012 Mierīgi var bez regexpa. Pametīšu ideju: function rep($str){ $len = strlen($str); for($i=0;$i<$len-3;$i++){ $c1 = substr($str, $i, 1); $c2 = substr($str, $i+1, 1); $c3 = substr($str, $i+2, 1); if($c1 === $c2 && $c2 === $c3){ return false; } } return true; } Quote Link to comment Share on other sites More sharing options...
Kavacky Posted June 5, 2012 Report Share Posted June 5, 2012 (edited) Gandrīz strādā: <?php $words = array( 'lol', 'lool', 'loool', 'looool', ); foreach ($words as $w) { $matches = array(); preg_match("/(.)\g{1}+/i", $w, $matches); foreach ($matches as $m) { if (strlen($m) == 3) { echo 'invalid'; break; } } echo ' (', $w, ')<br>'; } Edited June 5, 2012 by Kavacky Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 5, 2012 Report Share Posted June 5, 2012 Nav iespējams... nu ja. `(?:([a-z0-9])\1{2,})` Quote Link to comment Share on other sites More sharing options...
briedis Posted June 5, 2012 Report Share Posted June 5, 2012 Kavacky, daGrevis, un kā būs ar utf-8? Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 5, 2012 Report Share Posted June 5, 2012 Nu, kur problēma? `(?:(.)\1{2,})` Briedi, pamācies regexus — un tikai tad saki, ka nevar X vai Y ar tiem izdarīt. #burn P.S. Vai varbūt tev vajag, lai mečo tikai UTF-8 burtus? Arī var. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 5, 2012 Report Share Posted June 5, 2012 `/(?:(\pL)\1{2,})/uD` Kods, outputs. Quote Link to comment Share on other sites More sharing options...
briedis Posted June 5, 2012 Report Share Posted June 5, 2012 Briedi, pamācies regexus — un tikai tad saki, ka nevar X vai Y ar tiem izdarīt. #burn burn šmurn, es nevienā brīdī neteicu, ka tas nav izdarās, bet teicu, ka uz sitiena nevaru izdomāt :) Quote Link to comment Share on other sites More sharing options...
Kavacky Posted June 5, 2012 Report Share Posted June 5, 2012 There, I fixed it: + 'lāāĀl', - preg_match("/(.)(\g{1}+)/i", $w, $matches); + preg_match("/(.)(\g{1}+)/u", $w, $matches); - if (strlen($m) == 3) + if (mb_strlen($m, 'UTF-8') == 3) <?php $words = array( 'lāl', 'lāāl', 'lāāāl', 'lāāĀl', 'lāāāāl', ); foreach ($words as $w) { $matches = array(); preg_match("/(.)(\g{1}+)/u", $w, $matches); foreach ($matches as $m) { if (mb_strlen($m, 'UTF-8') == 3) { echo 'invalid'; break; } } echo ' (', $w, ')<br>'; } Quote Link to comment Share on other sites More sharing options...
rpr Posted June 7, 2012 Report Share Posted June 7, 2012 risinājums ir asprātīgs, bet ko īsti nozīmē "?:" Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 7, 2012 Report Share Posted June 7, 2012 http://www.regular-expressions.info/refadv.html Quote Link to comment Share on other sites More sharing options...
rpr Posted June 8, 2012 Report Share Posted June 8, 2012 manupraat var iztikt bez taam aareejaam iekavaam un tad nevajag arii to ?: un viss izskataas daudz saprotamaak. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.