{"id":13495204,"url":"https://github.com/jeffreyshen19/RegEx-Snippets","last_synced_at":"2025-03-28T16:31:50.390Z","repository":{"id":92391247,"uuid":"115769608","full_name":"jeffreyshen19/RegEx-Snippets","owner":"jeffreyshen19","description":"Organized list of useful RegEx snippets","archived":false,"fork":false,"pushed_at":"2020-06-10T17:18:41.000Z","size":34,"stargazers_count":119,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-01T19:54:16.577Z","etag":null,"topics":["list","regex","snippets"],"latest_commit_sha":null,"homepage":"https://jeffreyshen19.github.io/RegEx-Snippets/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffreyshen19.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-30T02:56:00.000Z","updated_at":"2024-07-06T20:30:29.000Z","dependencies_parsed_at":"2023-05-17T02:30:42.995Z","dependency_job_id":null,"html_url":"https://github.com/jeffreyshen19/RegEx-Snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyshen19%2FRegEx-Snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyshen19%2FRegEx-Snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyshen19%2FRegEx-Snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyshen19%2FRegEx-Snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffreyshen19","download_url":"https://codeload.github.com/jeffreyshen19/RegEx-Snippets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222395749,"owners_count":16977619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["list","regex","snippets"],"created_at":"2024-07-31T19:01:32.429Z","updated_at":"2024-10-31T10:30:42.596Z","avatar_url":"https://github.com/jeffreyshen19.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# RegEx Snippets\nUseful RegEx snippets that are categorized and searchable (see below)\n* **Contributions are welcome**! Please read our CONTRIBUTING, CODE_OF_CONDUCT, and LICENSE files to get started. RegEx snippet ideas are located in IDEAS.md.\n* **Errors?** Submit an issue, or even better, submit a PR fixing the issue!\n* RegEx snippets are either user-created, or picked from across the web.\n\n## Table of Contents\n\n* [Dates](#dates)\n  * Match mm/dd/yyyy\n  * Match mon/dd/yyyy\n  * Match month names\n* [Files](#files)\n  * Match image filenames\n* [Miscellaneous](#miscellaneous)\n  * Match city, state abbreviation\n  * Match credit cards\n  * Match email addresses\n  * Match US Phone Numbers\n  * Match valid hexadecimal colors\n  * Match social security number\n  * Match ZIP Codes (5 digit and 9 digit)\n* [Numbers](#numbers)\n  * Match dollar signs and comma separators in a number\n  * Matching leading zeroes\n* [Strings](#strings)\n  * Match new lines\n  * Match strong passwords (At least one lower case, one upper case, one number, one special character, and 10 characters long)\n  * Match usernames (alphanumeric string of a certain length)\n* [Web](#web)\n  * Extract URL from an anchor tag\n  * Match all content within a specific HTML tag\n  * Match all HTML tags\n  * Match IPv4 Addresses\n  * Match Twitter usernames\n  * Match URLs\n  * Match URL safe strings\n  * Match URL slugs\n\n## Snippets\n\n### Dates \u003ca name=\"dates\"\u003e\u003c/a\u003e\n**Match mm/dd/yyyy**  \nAccepts mm/dd/yyyy, mm-dd-yyyy, or mm.dd.yyyy and doesn't care about leading zeroes.\n```\n/^[0-3]?[0-9](\\/|\\.|-)[0-3]?[0-9](\\/|\\.|-)[1-9]\\d{3}$/gi\n```\n\n**Match mon/dd/yyyy**  \nAccepts mon/dd/yyyy, mon-dd-yyyy, or mon.dd.yyyy and doesn't care about leading zeroes or case. For example, will match \"jan/10/2017\"\n```\n/^(jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec)(\\/|\\.|-)[0-3]?[0-9](\\/|\\.|-)[1-9]\\d{3}$/gi\n```\n\n**Match month names**  \nAccepts month names (both full and abbreviated), and doesn't care about case. For example, it will match \"January\" and \"jan\".\n```\n/^(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;\n```\n\n\n---\n\n### Files \u003ca name=\"files\"\u003e\u003c/a\u003e\n**Match image filenames**\n```\n/^.+\\.(jpg|jpeg|png|gif|bmp|svg)$/gi\n```\n\n---\n\n### Miscellaneous \u003ca name=\"miscellaneous\"\u003e\u003c/a\u003e\n**Match city, state abbreviation** (Matches \"Los Angeles, CA\" for example)\n```\n/[a-zA-Z\\s]*, [A-Z][A-Z]/\n```\n\n**Match credit cards** (Make sure to strip the string of all commas, spaces, etc. before matching)  \nAmex:\n```\n/^3[47][0-9]{13}$/\n```\n\nDiscover:\n```\n/^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$/\n```\n\nMastercard:\n```\n/^5[1-5][0-9]{14}$/\n```\n\nVisa:\n```\n/^4[0-9]{12}(?:[0-9]{3})?$/\n```\n\nVisa Mastercard:\n```\n/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14})$/\n```\n\n**Match email addresses**\n```\n/^(([^\u003c\u003e()\\[\\]\\\\.,;:\\s@\"]+(\\.[^\u003c\u003e()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/i\n```\n\n**Match US Phone Numbers**  \nMatches ###-###-####, (###) ###-####, and ### ### ####\n```\n/^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$/\n```\n\n**Match valid hexadecimal colors**\n```\n/^#([0-9a-f]{3}$|[0-9a-f]{6}$)/i\n```\n\n**Match social security number**  \nMatches ###-##-####\n```\n/^[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}$/\n```\n\n**Match ZIP Codes (5 digit and 9 digit)**\n```\n/^[0-9]{5}(-[0-9]{4})?$/\n```\n\n---\n\n### Numbers \u003ca name=\"numbers\"\u003e\u003c/a\u003e\n\n**Match dollar signs and comma separators in a number**:\nThis can be used to strip a number string into an actual number.\n```\n/(\\$|\\,)/g\n```\n\n**Matching leading zeroes**:    \n```\n/^0{2,}/g\n```\n\n---\n\n### Strings \u003ca name=\"strings\"\u003e\u003c/a\u003e\n\n**Match new lines**\n```\n/[\\r\\n]|$/g\n```\n\n**Match strong passwords (At least one lower case, one upper case, one number, one special character, and 10 characters long)**:\n```\n/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?\u0026_])[A-Za-z\\d$@$!%*?\u0026_]{10,}$/\n```\n\n**Match usernames (alphanumeric string of a certain length)**:  \nReplace MIN_CHARS and MAX_CHARS with the minimum and maximum length of the username, respectively.\n```\n/^[a-z0-9]{MIN_CHARS,MAX_CHARS}$/i\n```\n\n---\n\n### Web \u003ca name=\"web\"\u003e\u003c/a\u003e\n\n**Extract URL from an anchor tag**  \nFor example, if `str` = \"\u0026lt;a href = 'https://www.google.com' \u0026gt;\u0026lt;/a\u0026gt;\", this RegEx would return \"https://www.google.com\".  \n\n```\nstr.match(/\u003ca\\s+(?:[^\u003e]*?\\s+)?href ?= ?[\"']([^'^\"]*)[\"'][^\u003e]*\u003e/i)[1]\n```\n\n**Match all content within a specific HTML tag** (*Replace \"p\" with whatever tag you want*)\n```\n/\u003cp\u003e(\\n|.)*\u003c\\/p\u003e/gi\n```\n\n**Match HTML tags**\n```\n/\u003c\\/?[^\u003e]+\u003e/g\n```\n\n**Match IPv4 Addresses**\n```\n/^((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]?)$/\n```\n\n**Match Twitter Usernames**\n```\n/^@?(\\w){1,15}$/\n```\n\n**Match URLs**\n```\n/((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:\u0026=\\+\\$,\\w]+@)?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:\u0026=\\+\\$,\\w]+@)[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-_]*)?\\??(?:[\\-\\+=\u0026;%@\\.\\w_]*)#?(?:[\\.\\!\\/\\\\\\w]*))?)/\n```\n\n**Match URL safe strings**\n```\n/^[a-zA-Z0-9_-]*$/\n```\n\n**Match URL Slug**\n```\n/^[a-z0-9-_]+$/i\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffreyshen19%2FRegEx-Snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffreyshen19%2FRegEx-Snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffreyshen19%2FRegEx-Snippets/lists"}