Skip to content

Instantly share code, notes, and snippets.

@MakStashkevich
Last active August 27, 2020 17:02
Show Gist options
  • Save MakStashkevich/1159d1460a9cce5f6bf9cc60818bae7b to your computer and use it in GitHub Desktop.
Save MakStashkevich/1159d1460a9cce5f6bf9cc60818bae7b to your computer and use it in GitHub Desktop.
Clear text to use en\ru\uk\bel languages
<?php
$message = 'test^т е с т^456%:7?Ũ₦NⓃⓝўї中文'';
if (preg_match_all('/[' .
'\x{0041}-\x{005A}\x{0061}-\x{007A}' . // all english lang letters
'\x{0410}-\x{044F}\x{0451}\x{0401}' . // all russian lang letters (include Ё)
'\x{040E}\x{045E}' . // belorussian lang letters (ў)
'\x{0404}\x{0454}\x{0406}\x{0456}\x{0407}\x{0457}' . // all ukrainian lang letters (ї etc)
'\x{0020}-\x{0040}' . // other support symbols (#@$! etc) (include space)
'\x{005B}-\x{005F}' . // ASCII Punctuation
'\x{00A7}' . // support § symbol to correct work colors on minecraft
']+/u', $message, $matches) > 0) {
$message = implode('', current($matches));
}
// online regex tests: https://regex101.com/r/m0d7TI/1
// result: testт е с т456%:7?ўї
// speed test result: ~0.00013s
// sources:
// https://en.wikipedia.org/wiki/List_of_Unicode_characters
// https://www.regular-expressions.info/unicode.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment