File size: 3,314 Bytes
022d340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import re

replace_list = [
    (r"’", "'"),  # Text decoding errors
    (r"â€[œ]?", '"'),  # Text decoding errors
    (  # Emoticons, HTML tag patterns, and special character sequences
        r"¯\\_\(ツ\)_\/¯|&#8203;|</?sp.n>|\?\u200d[♀♂]|\*††\*\*",
        "",
    ),
    (  # Miscellaneous symbols
        r"[\u260e\u2610\u2611\u261e\u2620\u2639\u2640\u2642\u2661\u2665\u267b\u26a0\u26d4]",
        "",
    ),
    (  # Dingbats # Miscellaneous symbols
        r"[\u2705\u270a\u270c\u270d\u2714\u2757\u2764\u2795\u2797\u27a1]",
        "",
    ),
    (  # General punctuations and formatting characters
        r"[\u200b-\u200d\u2022\u202a\u2028\u2039\u203a\u2060-\u2069]",
        "",
    ),
    (r"[\u00a7\u00a9\u00ab-\u00ae\u00b0\u00b7\u00bb\u00bf]", ""),  # Latin supplements
    (r"[\u0000\u0006-\u0008\u000b-\u001f\u0080-\u009f]", ""),  # Control characters
    (r"[\u3040-\u9fff\uac00-\ud7ff]", ""),  # CJK characters
    (r"[\u2592\u25a0\u25cb\u25cf]", ""),  # Box elements / geometric shapes
    (r"[\U0001f000-\U0001ffff]", ""),  # Emoji etc.
    (r"[\ue000-\uf8ff]", ""),  # Private use area
    (r"[\ufe00-\ufe0f]", ""),  # Variation selectors
    (r"[\u032a\u034f]", ""),  # Combining diacritical marks
    (r"[\u061c\u0640]", ""),  # Arabic
    (r"[\u0d9a\u0dd4]", ""),  # Sinhala
    (r"[\u2116\u2122]", ""),  # Letter-like symbols
    (r"[\u2211\u22ef]", ""),  # Mathematical operators
    (r"[\u2b07\u2b55]", ""),  # Miscellaneous symbols and arrows
    (r"[\uff0a\uff5e]", ""),  # Halfwidth and fullwidth forms
    (r"[\u02c4]", ""),  # Modifier letter up arrowhead
    (r"[\u2076]", ""),  # Superscript six
    (r"[\u20e3]", ""),  # Combining enclosing keycap
    (r"[\u2191]", ""),  # Upwards arrow
    (r"[\u2320]", ""),  # Top half integral
    (r"[\ufeff]", ""),  # Zero width no-break space
    (r"[\u00a0\u2002-\u200a\u3000]", " "),  # Special space characters
    (  # Small quotation mark, accent mark, or prime symbol
        r"[\u00b4\u02bb\u02cb\u2018\u2019\u2032]",
        "'",
    ),
    (  # Diaeresis, double quotation mark, or double prime symbol
        r"[\u00a8\u201c\u201d\u2033\u275d\u275e]",
        '"',
    ),
    (  # Various types of hyphens, dashes, or the minus sign
        r"[\u2010\u2011\u2013\u2014\u2015\u2212]",
        "-",
    ),
    (r"[\u201a\u201e\uff0c]", ","),  # Low quotation mark or a fullwidth comma
    (r"[\u203c\uff01]", "!"),  # Double exclamation mark or a fullwidth exclamation mark
    (r"[\u300a\u3010\uff08]", "("),  # Various types of left brackets
    (r"[\u300b\u3011\uff09]", ")"),  # Various types of right brackets
    (r"[\u2248\uff1d]", "="),  # Various types of equals sign
    (r"[\u2026]", "..."),  # Horizontal ellipsis
    (r"[\uff1a]", ":"),  # Fullwidth colon
    (r"[\uff1b]", ";"),  # Fullwidth semicolon
    (r"[\u00d7]", "x"),  # Multiplication sign
    (r"[13][a-km-zA-HJ-NP-Z1-9]{25,34}", ""),  # Bitcoin addresses
    (r"[\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4}", ""),  # Email addresses
]


def preprocess_text(text: str) -> str:
    for pattern, repl in replace_list:
        text = re.sub(pattern, repl, text)
    return text


if __name__ == "__main__":
    preprocess_text(
        "【 Reminder 】 Your system devices has been Hacked 【 National Security Agency 】 Authority-11622272"
    )