TextFormat: make colour matching regex less absurd

This commit is contained in:
Dylan K. Taylor 2018-02-07 11:31:49 +00:00
parent 266d1cb935
commit dbac2abafb

View File

@ -62,7 +62,7 @@ abstract class TextFormat{
* @return array
*/
public static function tokenize(string $string) : array{
return preg_split("/(" . TextFormat::ESCAPE . "[0123456789abcdefklmnor])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
return preg_split("/(" . TextFormat::ESCAPE . "[0-9a-fk-or])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
}
/**
@ -75,7 +75,7 @@ abstract class TextFormat{
*/
public static function clean(string $string, bool $removeFormat = true) : string{
if($removeFormat){
return str_replace(TextFormat::ESCAPE, "", preg_replace(["/" . TextFormat::ESCAPE . "[0123456789abcdefklmnor]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string));
return str_replace(TextFormat::ESCAPE, "", preg_replace(["/" . TextFormat::ESCAPE . "[0-9a-fk-or]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string));
}
return str_replace("\x1b", "", preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string));
}