1
+ const output = document . getElementById ( "regex-output" )
2
+ const input = document . getElementById ( "word-input" )
3
+ const error_length = document . getElementById ( "regex-error-toolong" )
4
+
5
+ const checkbox_num = document . getElementById ( "filter-num" )
6
+ const checkbox_sym = document . getElementById ( "filter-sym" )
7
+ const checkbox_let = document . getElementById ( "filter-let" )
8
+ const checkbox_emo = document . getElementById ( "filter-emo" )
9
+ const checkbox_dub = document . getElementById ( "double-spm" )
10
+ const checkbox_mul = document . getElementById ( "multi-char" )
11
+ const checkbox_vow = document . getElementById ( "vowel-less" )
12
+ const checkbox_whi = document . getElementById ( "whitespace" )
13
+
14
+ const numReplacers = {
15
+ "i" : [ "1" ] ,
16
+ "l" : [ "1" ] ,
17
+ "e" : [ "3" ] ,
18
+ "a" : [ "4" ] ,
19
+ "t" : [ "7" ] ,
20
+ "b" : [ "8" ] ,
21
+ "g" : [ "9" ] ,
22
+ "o" : [ "0" ]
23
+ } ;
24
+
25
+ const symReplacers = {
26
+ "i" : [ "!" , "|" ] ,
27
+ "l" : [ "!" , "|" ] ,
28
+ "s" : [ "\\$" ] ,
29
+ "h" : [ "\\|-\\|" ] ,
30
+ "n" : [ "|\\|" ] ,
31
+ "c" : [ "\\(" ] ,
32
+ "k" : [ "\\|<" ] ,
33
+ "a" : [ "@" , "∆" , "/-\\" , "/_\\" , "/\\" , "Д" ] ,
34
+ "b" : [ "|}" , "|:" , "|8" , "ß" , "ь" ]
35
+ } ;
36
+
37
+ const letReplacers = {
38
+ "i" : [ "l" ] ,
39
+ "l" : [ "i" ] ,
40
+ "u" : [ "v" ] ,
41
+ "m" : [ "nn" , "rn" ] ,
42
+ "w" : [ "vv" , "uu" ]
43
+ } ;
44
+
45
+ const emoReplacers = {
46
+ "a" : [ "🇦" , "🅰️" ] ,
47
+ "b" : [ "🇧" , "🅱️" ] ,
48
+ "c" : [ "🇨" , "©️" ] ,
49
+ "d" : [ "🇩" ] ,
50
+ "e" : [ "🇪" ] ,
51
+ "f" : [ "🇫" ] ,
52
+ "g" : [ "🇬" ] ,
53
+ "h" : [ "🇭" ] ,
54
+ "i" : [ "🇮" , "ℹ️" ] ,
55
+ "j" : [ "🇯" ] ,
56
+ "k" : [ "🇰" ] ,
57
+ "l" : [ "🇱" ] ,
58
+ "m" : [ "🇲" , "Ⓜ️" ] ,
59
+ "n" : [ "🇳" ] ,
60
+ "o" : [ "🇴" , "🅾️⭕" ] ,
61
+ "p" : [ "🇵" , "🅿️" ] ,
62
+ "q" : [ "🇶" ] ,
63
+ "r" : [ "🇷" , "®️" ] ,
64
+ "s" : [ "🇸" ] ,
65
+ "t" : [ "🇹" , "✝️" ] ,
66
+ "u" : [ "🇺" ] ,
67
+ "v" : [ "🇻" ] ,
68
+ "w" : [ "🇼" ] ,
69
+ "x" : [ "🇽" , "❌" , "❎" , "✖️" ] ,
70
+ "y" : [ "🇾" ] ,
71
+ "z" : [ "🇿" ] ,
72
+ "1" : [ "1️⃣" ] ,
73
+ "2" : [ "2️⃣" ] ,
74
+ "3" : [ "3️⃣" ] ,
75
+ "4" : [ "4️⃣" ] ,
76
+ "5" : [ "5️⃣" ] ,
77
+ "6" : [ "6️⃣" ] ,
78
+ "7" : [ "7️⃣" ] ,
79
+ "8" : [ "8️⃣" ] ,
80
+ "9" : [ "9️⃣" ] ,
81
+ "0" : [ "0️⃣" ]
82
+ } ;
83
+
84
+ function updateRegex ( ) {
85
+ let start_text ;
86
+ if ( ! input . value == "" ) {
87
+ start_text = input . value . toLowerCase ( ) ;
88
+ } else {
89
+ start_text = "hello world" ;
90
+ } ;
91
+
92
+ let end_text = "" ;
93
+ let previous_charater ;
94
+ let previous_charater_combo = 0 ;
95
+ let previous_charater_modified = false ;
96
+ for ( var i = 0 ; i < start_text . length ; i ++ ) {
97
+ let character = ( start_text [ i ] ) ;
98
+ let replacers = [ ] ;
99
+
100
+ if ( character == previous_charater & previous_charater_modified ) {
101
+ previous_charater_combo ++ ;
102
+ continue ;
103
+ } else if ( previous_charater_combo > 0 & previous_charater_modified ) {
104
+ if ( checkbox_dub . checked ) {
105
+ end_text = end_text . concat ( `{${ previous_charater_combo + 1 } ,}` ) ;
106
+ } else {
107
+ end_text = end_text . concat ( `{${ previous_charater_combo + 1 } , ${ previous_charater_combo + 1 } }` ) ;
108
+ }
109
+ previous_charater_combo = 0 ;
110
+ previous_charater_modified = false ;
111
+ } ;
112
+
113
+ if ( checkbox_num . checked ) {
114
+ const numbers = numReplacers [ character ] ;
115
+ if ( numbers ) {
116
+ for ( var i2 = 0 ; i2 < numbers . length ; i2 ++ ) {
117
+ replacers . push ( numbers [ i2 ] ) ;
118
+ } ;
119
+ } ;
120
+ } ;
121
+
122
+ if ( checkbox_sym . checked ) {
123
+ const symbols = symReplacers [ character ] ;
124
+ if ( symbols ) {
125
+ for ( var i2 = 0 ; i2 < symbols . length ; i2 ++ ) {
126
+ replacers . push ( symbols [ i2 ] ) ;
127
+ } ;
128
+ } ;
129
+ } ;
130
+
131
+ if ( checkbox_let . checked ) {
132
+ const letters = letReplacers [ character ] ;
133
+ if ( letters ) {
134
+ for ( var i2 = 0 ; i2 < letters . length ; i2 ++ ) {
135
+ replacers . push ( letters [ i2 ] ) ;
136
+ } ;
137
+ } ;
138
+ } ;
139
+
140
+ if ( checkbox_emo . checked ) {
141
+ const emojis = emoReplacers [ character ] ;
142
+ if ( emojis ) {
143
+ for ( var i2 = 0 ; i2 < emojis . length ; i2 ++ ) {
144
+ replacers . push ( emojis [ i2 ] ) ;
145
+ } ;
146
+ } ;
147
+ } ;
148
+
149
+ let is_all_one_char = true
150
+ for ( var i2 = 0 ; i2 < replacers . length ; i2 ++ ) {
151
+ let replacer = replacers [ i2 ] ;
152
+
153
+ if ( replacer == null ) { break }
154
+
155
+ if ( replacer . replace ( "\\" , "" ) . length > 1 & checkbox_mul . checked ) {
156
+ is_all_one_char = false
157
+ } else if ( / \p{ Extended_Pictographic} / u. test ( replacer ) ) {
158
+ //pass
159
+ } else if ( replacer . length > 2 ) {
160
+ replacers . splice ( i2 , 1 )
161
+ i2 --
162
+ }
163
+ } ;
164
+
165
+ if ( checkbox_whi . checked & ! end_text == "" ) {
166
+ end_text = end_text . concat ( "\\s*" )
167
+ }
168
+ if ( replacers . length == 0 ) {
169
+ end_text = end_text . concat ( character ) ;
170
+ } else {
171
+ if ( is_all_one_char ) {
172
+ end_text = end_text . concat ( `[${ character } ${ replacers . join ( '' ) } ]` ) ;
173
+ } else {
174
+ end_text = end_text . concat ( `(${ character } |${ replacers . join ( '|' ) } )` ) ;
175
+ }
176
+ previous_charater_modified = true ;
177
+ } ;
178
+
179
+ if ( checkbox_vow . checked & ( character == "a" || character == "e" || character == "i" || character == "o" || character == "u" ) ) {
180
+ end_text = end_text . concat ( "?" )
181
+ } ;
182
+
183
+ previous_charater = character ;
184
+ } ;
185
+
186
+ if ( previous_charater_combo > 0 & previous_charater_modified ) {
187
+ if ( checkbox_dub . checked ) {
188
+ end_text = end_text . concat ( `{${ previous_charater_combo + 1 } ,}` ) ;
189
+ } else {
190
+ end_text = end_text . concat ( `{${ previous_charater_combo + 1 } , ${ previous_charater_combo + 1 } }` ) ;
191
+ }
192
+ previous_charater_combo = 0 ;
193
+ previous_charater_modified = false ;
194
+ } ;
195
+
196
+ if ( end_text . length > 260 ) {
197
+ error_length . hidden = false
198
+ } else {
199
+ error_length . hidden = true
200
+ }
201
+
202
+ output . innerText = end_text ;
203
+ }
204
+
205
+ input . oninput = updateRegex
206
+ checkbox_num . onchange = updateRegex
207
+ checkbox_sym . onchange = updateRegex
208
+ checkbox_let . onchange = updateRegex
209
+ checkbox_dub . onchange = updateRegex
210
+ checkbox_mul . onchange = updateRegex
211
+ checkbox_vow . onchange = updateRegex
212
+ checkbox_whi . onchange = updateRegex
213
+ checkbox_emo . onchange = updateRegex
214
+ updateRegex ( )
0 commit comments