> For the complete documentation index, see [llms.txt](https://overfinch.gitbook.io/cheatsheet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overfinch.gitbook.io/cheatsheet/regex.md).

# RegEx

#### Очистка

{% code title="чистит все дивы от лишних стилей классов и айди получается чистеньий код" %}

```php
$description[0] = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $description[0]);
```

{% endcode %}

#### Обрезка

<pre class="language-php" data-title="обрезать до определенного символа"><code class="lang-php"><strong>//$row - строка которую нужно обрезать
</strong>// | - символ по который обрежится строка
$str=strpos($row, "|"); 
$row=substr($row, 0, $str); 
</code></pre>

{% code title="Обрезать расширение файла" %}

```php
$ext = end(explode(".", $filename));
```

{% endcode %}

{% code title="Обрезать текст по количеству слов" %}

```php
$text = strip_tags($item['text']);
$arr = explode( ' ', $text );
$arr = array_slice( $arr, 0, 40 );
$text = implode( ' ', $arr ).'...'; // Этот текст нужно обработать как...
unset($arr);
$content[$i]['text'] = $text;
```

{% endcode %}
