[Solved] PHP Regex extract everything except newlines and tabs


In PHP you can do:

<?php
$string = "\n
\t\t\t\t\tÁrea útil\n
\t\t\t\t\t\n
\t\t\t\t\t\t\n
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t150 m²\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n
\t\t\t\t\t\n
\t\t\t\t";

// Get rid of the tabs
$string = preg_replace( '/(\t)/m', '', $string );

// Split on new lines
$array = preg_split( '/[\r\n]/m', $string );

// Loop the array and get rid of empty strings
foreach( $array as $k=>$v )
{
    if( $v === '' )
    {
        unset( $array[ $k ] );
    }
}

// Re-index the array
$array = array_values( $array );

var_dump( $array );

Which outputs:

array(2) {
  [0]=>
  string(11) "Área útil"
  [1]=>
  string(7) "150 m²"
}

1

solved PHP Regex extract everything except newlines and tabs