-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathregexsnippets.code-snippets
323 lines (323 loc) · 17.7 KB
/
regexsnippets.code-snippets
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
{
"Validate E-Mail Address": {
"prefix": "!valemail",
"body": "/^[A-Z0-9!#$%&'*+/=?^_`{|}~-][A-Z0-9!#$%&'*+/=?^_`{|}~.-]*[A-Z0-9!#$%&'*+/=?^_`{|}~-]@[A-Z0-9][A-Z0-9-]*\\.[A-Z0-9-]*[A-Z0-9]$/igm",
"description": "Validates the given email address"
},
"Validate Hexadecimal Color Value": {
"prefix": "!valhexcol",
"body": "^#(?:[0-9a-fA-F]{3}){1,2}$",
"description": "Validates the given string to check if it is a valid Hexadecimal Color Value"
},
"Password Strength Validator": {
"prefix": "!valpass",
"body": "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?&_])[A-Za-z\\d$@$!%*?&_]{${1:minlength},${2:maxlength}}$/",
"description": "Validates the provided password to check if it contains atleast 1 Upper Case, 1 Lower Case, 1 Special Char, 1 Number. The min value represents the minimum length and max represents maximum length"
},
"Validate ISBN Number": {
"prefix": "!valisbn",
"body": "/\\b(?:ISBN(?:: ?| ))?((?:97[89])?\\d{9}[\\dx])\\b/i",
"description": "Validates the given ISBN Number"
},
"Validate IPV4 Address": {
"prefix": "!valipv4",
"body": "/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b/",
"description": "Validates the given IPV4 address"
},
"Validate IPV6 Address": {
"prefix": "!valipv6",
"body": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",
"description": "Validates the given IPV6 address"
},
"Validate Date In mm/dd/yy": {
"prefix": "!valmmddyy",
"body": "/^[0-3]?[0-9](/|\\.|-)[0-3]?[0-9](/|\\.|-)[1-9]\\d{3}$/gi",
"description": "Validate the given date in dd/mm/yy (Does not care about the separator or the leading zeros)"
},
"Validate Date In mon/dd/yyyy": {
"prefix": "!valmonddyyyy",
"body": "/^(jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec)(/|\\.|-)[0-3]?[0-9](/|\\.|-)[1-9]\\d{3}$/gi",
"description": "Validates the given date in mon/dd/yyyy format (Ex: jan/23/2019)"
},
"Validate Month Name": {
"prefix": "!valmonth",
"body": "/^(jan(uary)?|feb(ruary)?|(mar)?ch|(apr)?il|may|(jun)?e|(jul)?y|(aug)?ust|sep(tember)?|sept|(oct)?ober|(nov)?ember|(dec)?ember)$/i;",
"description": "Validates month name both in full and abbreviated form (Ex: February or Feb)"
},
"Extract Price From String": {
"prefix": "!extprice",
"body": "(\\\\${1:currency_symbol}\\s?[0-9,]+(\\.[0-9]{2})?)",
"description": "Extract price value from any string (Add your currency symbol in the marked area)"
},
"Parse 'To' From E-mail Header": {
"prefix": "!parehead",
"body": "/\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,6}\\b/i",
"description": "Parse an email header and retrieve 'To' value from it"
},
"Validate Facebook Profile Link": {
"prefix": "!valfblink",
"body": "(?:http:\\/\\/)?(?:www\\.)?facebook\\.com/(?:(?:\\w)*#!/)?(?:pages/)?(?:[\\w\\-]*/)*([\\w\\-]*)",
"description": "Validate the given facebook profile link"
},
"Validate Credit Card Number": {
"prefix": "!valcc",
"body": "^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$",
"description": "Validates Credit Card Number (Does'nt check for fake numbers) Supported Cards: Visa, MasterCard, American Express, Diners Club, Discover, and JCB"
},
"Validate Alphanumeric Username": {
"prefix": "!valusername",
"body": "/^[a-z0-9]{${1:MIN_CHARS},${2:MAX_CHARS}}$/i",
"description": "Simple Regex to validate an alphanumeric string based on the max and min length values"
},
"Extract URL From String": {
"prefix": "!exturl",
"body": "(http|ftp|https):\\/\\/([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?",
"description": "Extract an URL from any string (With HTTP)"
},
"Get Internet Explorer Version": {
"prefix": "!getiever",
"body": "^.*MSIE [5-8](?:\\.[0-9]+)?(?!.*Trident/[5-9]\\.0).*$",
"description": "Get the version of Internet Explorer Being Used (To be used with a browser agent)"
},
"Validate Image Filenames": {
"prefix": "!valimage",
"body": "/^.+\\.(${1:jpg|jpeg|png|gif|bmp|svg})$/gi",
"description": "Validate the name of the image file (delete the names which are not requrired"
},
"Validate Words With Abbreviations": {
"prefix": "!valcityabbr",
"body": "/[a-zA-Z\\s]*, [A-Z][A-Z]/",
"description": "Validate words with abbreviated first 2 letters (Ex: California, CA)"
},
"Validate US Phone Numbers": {
"prefix": "!valusphone",
"body": "/^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$/",
"description": "Validate US Phone Numbers"
},
"Validate Social Security Number": {
"prefix": "!valssn",
"body": "/^[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}$/",
"description": "Validate the given Social Security Number"
},
"Validate Zip Codes (5 or 9 digits)": {
"prefix": "!valzip",
"body": "/^[0-9]{5}(-[0-9]{4})?$/",
"description": "Validate the given Zip Code(5 or 9 digits only)"
},
"Match Anything Between HTML Tags": {
"prefix": "!valhtmlcont",
"body": "/<${1:tag_name}>(\\n|.)*</${1:tag_name}>/gi",
"description": "Will verify if the provided string contains that HTML tag with any content between them"
},
"Validate HTML Tag": {
"prefix": "!valhtmltag",
"body": "/</?[^>]+>/g",
"description": "Will verify if the provided string has either opening or closing html tags (Does not verify the valdity of the HTML Tag)"
},
"Validate Twitter Username": {
"prefix": "!valtwitter",
"body": "/^@?(\\w){1,15}$/",
"description": "Validates if the given string is a valid twitter username"
},
"Validate URL": {
"prefix": "!valurl",
"body": "/^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:[/?#]\\S*)?$/i",
"description": "Validates if the given string is a valid URL"
},
"Validate Google Search Syntax": {
"prefix": "!valgooglesyn",
"body": "/([+-]?(?:'.+?'|\".+?\"|[^+\\- ]{1}[^ ]*))/g",
"description": "Validates if the provided string is a valid google search syntax"
},
"Extract Media Query Properties": {
"prefix": "!extcssmedia",
"body": "/@media([^{]+)\\{([\\s\\S]+?})\\s*}/g",
"description": "Extract properties and values from CSS Media Queries"
},
"Remove HTML Comments From Code Block": {
"prefix": "!exthtmlcomms",
"body": "<!--(.*?)-->",
"description": "Strip all the comments from a HTML Code Block"
},
"Extract CSS Properties And Values": {
"prefix": "!extcss",
"body": "^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1}",
"description": "Extract individual CSS Properties from the given string"
},
"Extract Youtube Video ID From URL": {
"prefix": "!extytid",
"body": "/http:\\/\\/(?:youtu\\.be/|(?:[a-z]{2,3}\\.)?youtube\\.com/watch(?:\\?|#\\!)v=)([\\w-]{11}).*/gi",
"description": "Extract the video ID from a valid Youtube Link"
},
"Extract Image Source From Img Tag": {
"prefix": "!extimgsrc",
"body": "\\< *[img][^\\>]*[src] *= *[\"\\']{0,1}([^\"\\'\\ >]*)",
"description": "Extract the image's source from the provided HTML code block"
},
"Validate A Base64 String": {
"prefix": "!valbase64",
"body": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
"description": "Validate if the given string is Base64 compliant"
},
"Extract Domain Name From URL": {
"prefix": "!extdomain",
"body": "/https?:\\/\\/(?:[-\\w]+\\.)?([-\\w]+)\\.\\w+(?:\\.\\w+)?/?.*/i",
"description": "Extract the domain from a valid URL string"
},
"Seperate Thousands": {
"prefix": "!septhousand",
"body": "/\\d{1,3}(?=(\\d{3})+(?!\\d))/g",
"description": "Seperates the given numeric string with commas in thousands"
},
"Validate If Word/Char Exists": {
"prefix": "!valchars",
"body": "/${1: chars_to_be_searched}/",
"description": "Check if the string contains atleast one occurence of the provided search chars"
},
"Reduce Multiple Space To Single Space": {
"prefix": "!valspaces",
"body": "/\\s\\s+/g, ' '",
"description": "Converts multiple spaces to single spaces between all words in the given string"
},
"Extract Text Between Square Brackets": {
"prefix": "!extsqrbracks",
"body": "\\[([^]]+)\\]",
"description": "Extract the square brackets and the text between them from a string"
},
"Remove Alphanumeric Characters": {
"prefix": "!valalpnum",
"body": "/[^A-Za-z0-9 ]/",
"description": "Validate the given string for Non-Alphanumeric Characters"
},
"Extract JS/Angular Logs": {
"prefix": "!extlogs",
"body": "/^(\\s*)?[^/]{0,2}((\\$log|console)\\.(warn|log|info))(.*)$/gmi",
"description": "Regular Expression to find native Javascript console and AngularJS $log log warn or info that are NOT comments / commented out"
},
"Extract All Brackets With Contents": {
"prefix": "!extbrackscont",
"body": "/\\s*\\([^)]*\\)/', '",
"description": "Extract all brackets and the content between them from a given string"
},
"Add Links Tags To Strings That Are URLs": {
"prefix": "!addlinktag",
"body": "str.replace(/((http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?)/gi, '<a href=\"$1\">$1</a>');",
"description": "Adds Link Tags to all the strings that start with http or https (Full Function Provided)"
},
"Count The Number Of Ocurrences Of Chars In A String": {
"prefix": "!findocurrences",
"body": "(${1: string}.match(/${2: string_to_search}/g) || []).length;",
"description": "Provides a function to calculate the number of times the provided character(s) have appeared in the string (Returns 0 when no ocurrences found)"
},
"Validate UUID V1": {
"prefix": "!valuuidv1",
"body": "/^[0-9A-F]{8}-[0-9A-F]{4}-[1][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i",
"description": "Validates if the code is a valid UUID v1 code"
},
"Validate UUID V2": {
"prefix": "!valuuidv2",
"body": "/^[0-9A-F]{8}-[0-9A-F]{4}-[2][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i",
"description": "Validates if the code is a valid UUID v2 code"
},
"Validate UUID V3": {
"prefix": "!valuuidv3",
"body": "/^[0-9A-F]{8}-[0-9A-F]{4}-[3][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i",
"description": "Validates if the code is a valid UUID v3 code"
},
"Validate UUID V4": {
"prefix": "!valuuidv4",
"body": "/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i",
"description": "Validates if the code is a valid UUID v4 code"
},
"Validate UUID V5": {
"prefix": "!valuuidv5",
"body": "/^[0-9A-F]{8}-[0-9A-F]{4}-[5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i",
"description": "Validates if the code is a valid UUID v5 code"
},
"Extract Text Between Quotes": {
"prefix": "!extquotes",
"body": "([\"'])(?:(?=(\\?))\\2.)*?\\1",
"description": "Extracts any text between quotations (Works with nested quotes too)"
},
"Split String To n sized chunks": {
"prefix": "!splitnchunks",
"body": "/.{1,${1: end_size}}/g",
"description": "Splits the given string to n-sized chunks even if its size is not an exact multiple"
},
"Validate if the string ends with a particular character": {
"prefix": "!valendswith",
"body": "/.*[${1: character}]$/",
"description": "Checks if the provided string ends with the provided character"
},
"Convert to camelCase": {
"prefix": "!tocamel",
"body": "${1: string}.replace(/(?:^\\w|[A-Z]|\b\\w)/g, function(word, index) {return index === 0 ? word.toLowerCase() : word.toUpperCase();}).replace(/\\s+/g, '');",
"description": "Returns a function which converts the given string to camelCase"
},
"Balanced Paranthesis Validation": {
"prefix": "!valbracks",
"body": "\\((?>\\((?<c>)|[^()]+|\\)(?<-c>))*(?(c)(?!))\\)",
"description": "Validates if all paranthesis are properly balanced within the given string"
},
"Validate JWT": {
"prefix": "!valjwt",
"body": "^[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*$",
"description": "Validates if the given string is a valid JSON Web Token (JWT)"
},
//Regex code to validate if the string is a valid JSON
"Validate JSON": {
"prefix": "!valjson",
"body": "^\\{(\\s|\\n\\s)*((\"\\w*\"):(\\s)*(\"\\w*\"|\\d*|(\\{(\\s|\\n\\s)*((\"\\w*\"):(\\s)*(\"\\w*(,\\w+)*\"|\\d{1,}|\\[(\\s|\\n\\s)*(\\{(\\s|\\n\\s)*((\"\\w*\"):(\\s)*((\"\\w*\"|\\d{1,}))((,(\\s|\\n\\s)*\"\\w*\"):(\\s)*(\"\\w*\"|\\d{1,}))*(\\s|\\n)*\\})){1}(\\s|\\n\\s)*(,(\\s|\\n\\s)*\\{(\\s|\\n\\s)*((\"\\w*\"):(\\s)*((\"\\w*\"|\\d{1,}))((,(\\s|\\n\\s)*\"\\w*\"):(\\s)*(\"\\w*\"|\\d{1,}))*(\\s|\\n)*\\})?)*(\\s|\\n\\s)*\\]))((,(\\s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s|\\n\\s)*\"\\w*\"):(\"\\w*\"|\\d{1,}))*(\\s|\\n)*\\})?)*(\\s|\\n\\s)*\\]))*(\\s|\\n\\s)*\\}){1}))*(\\s|\\n)*\\}$",
"description": "Validates if the given string is a valid non array JSON"
},
"Validate Username of type test@test": {
"prefix": "!valspecialusername",
"body": "[^@/]+@[^@/]+",
"description": "Vlaidates if the given string is the form test@test"
},
"Multispace Replacement": {
"prefix": "!multispace",
"body": "\\s+",
"description": "Replaces all the spaces in the given string with a single space"
},
"Non-alphanumeric replacement": {
"prefix": "!nonalphanumeric",
"body": "[^a-zA-Z0-9]",
"description": "Replaces all the non-alphanumeric characters in the given string with a single space"
},
"Blank Line": {
"prefix": "!blankline",
"body": "^\\s*$",
"description": "Validates if the given string is a blank line"
},
"Positive integers": {
"prefix": "!positiveint",
"body": "^[1-9]+[0-9]*$",
"description": "Validates if the given string is a positive integer"
},
"Positive Decimal Values": {
"prefix": "!positivedecimal",
"body": "(^\\d*\\.?\\d*[0-9]+\\d*$)|(^[0-9]+\\d*\\.\\d*$)",
"description": "Validates if the given string is a positive decimal value"
},
"Positive Decimal Values with 1 decimal place": {
"prefix": "!positivedecimal1",
"body": "^\\d*\\.?\\d*[0-9]+\\d*$",
"description": "Validates if the given string is a positive decimal value with 1 decimal place"
},
"Social Security Number": {
"prefix": "!ssn",
"body": "[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}",
"description": "Validates if the given string is a valid social security number"
},
"Date": {
"prefix": "!valdate",
"body": "^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$",
"description": "Validates if the given string is a valid date"
},
"Replace Font Tags": {
"prefix": "!replacefont",
"body": "<(FONT|font)([ ]([a-zA-Z]+)=(\"|\\')[^\"\\\\']+(\"|\\'))*[^>]+>([^<]+)(<\/FONT>|<\/font>",
"description": "Replaces all the font tags in the given string with a single space"
}
}