DEV Community

Cover image for Check if a string contains Zalgo text
Limon Safayet
Limon Safayet

Posted on • Updated on

Check if a string contains Zalgo text

What is Zalgo Text?

Zalgo Text typically falls in the CC and CD Unicode ranges. Writings are going through irregular moves and these alterations are making them exceptionally prevalent. Nearly every week, we meet with a modern fashion of content. But a few of the content styles are profoundly acknowledged and utilized over the web. Memes are prevalent to utilize extraordinarily styled writings. A few styles make them appealing while a few make them see revolting, but their topic is arranged sometime recently utilizing them. In this way, a few meme-makers utilize peculiar content styles fair to form their meme scary. Among those weird styles, Zalgo text style is one of them.

How Zalgo text generator works

The Zalgo text generator adds symbols on top, beneath and in the middle of your text. Putting stuff in the middle is discouraged, because some browsers and system that are not as good with symbols, are going to turn some letters into squares then.

How to find is a string contains Zalgo text

Zalgo text is made from a multitude of Unicode diacritic marks. For that reason if anyone need to check if a string contains Zalgo text using this /[\xCC\xCD]/ regular expression you can check it. This is a example in JavaScript.

if ( str.match('/[\xCC\xCD]/') ) {
    alert('This is a Zalgo text');
 }
Enter fullscreen mode Exit fullscreen mode

This is in Python

import re

#Check if the string contains Zalgo text:

txt = "H̛̛͠ȩl̨̀͞l̨̨͘ơ̧ W͠͡͠or̶͜ld̀"
x = re.search("/[\xCC\xCD]/", txt)

if x:
  print("YES! This string contains Zalgo text!")
else:
  print("No match")
Enter fullscreen mode Exit fullscreen mode

This is in PHP

<?php
$str = "H̛̛͠ȩl̨̀͞l̨̨͘ơ̧ W͠͡͠or̶͜ld̀";
$pattern = "/[\xCC\xCD]/";
echo preg_match($pattern, $str); // Outputs 1
?>
Enter fullscreen mode Exit fullscreen mode

This is in C#

public bool IsZalgoText(String str)  
    {  
        Regex objNaturalPattern = new Regex("/[\xCC\xCD]/");  
        if(objNotNaturalPattern.IsMatch(str)){
          return true;
        } 
        else{
          return false;
        }
    }  
Enter fullscreen mode Exit fullscreen mode

Thanks and Happy Codding :)

Top comments (1)

Collapse
 
lim10dev profile image
lim10dev
public bool IsZalgoText(String str)  
    {  
        Regex objNaturalPattern = new Regex("/[\xCC\xCD]/");  
        return objNotNaturalPattern.IsMatch(str);
    }
Enter fullscreen mode Exit fullscreen mode

i think this should work too, saving an if statement :D