Salve sto provando ad estrarre da una stringa 6 numeri consecutivi
Esempio:
"prova 000123 altro testo 1214"
deve estrarre 000123 e basta
ho provato cosi
Non viene estratto solo la stringa desiderata.codice:public function esegui($row_csv) { $this->regularExpCheck('00123'); $this->regularExpCheck('12t123'); $this->regularExpCheck('456'); // mi deve restituire solo la sottostringa 000123 $this->regularExpCheck('prova 000123 altro testo'); // mi deve restituire solo la sottostringa 000123 $this->regularExpCheck('prova 000123 altro testo 1214'); } private function regularExpCheck($txt, $cifre = 6) { // 0-9 prende numeri da 0 a 9 e poi solo se sono di 6 cifre $regex = "/[(0-9)-{' . $cifre . '}]/"; preg_match_all($regex,$txt,$risultato); return false; }
Dove sbaglio?