mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
Initial commit
This commit is contained in:
110 files changed
+11734
No files matched your search
@@ -0,0 +1,31 @@
|
||||
export class RegexUtils {
|
||||
public static regex(input: string): RegExp {
|
||||
let match = input.match(/^\/(.*)\/([^/]*)$/);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new RegExp(match[1], match[2]);
|
||||
}
|
||||
|
||||
public static escapeRegex(input: string): string {
|
||||
return input?.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||
}
|
||||
|
||||
public static discordId(input: string): string {
|
||||
return input?.match(/\b\d{17,20}\b/)?.[0];
|
||||
}
|
||||
|
||||
public static tag(input: string): { username: string; tag: string; discriminator: string } {
|
||||
let match = input.match(/\b(.+)#([\d]{4})\b/);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
tag: match[0],
|
||||
username: match[1],
|
||||
discriminator: match[2],
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user