{"id":20619897,"url":"https://github.com/mafda/regex_101","last_synced_at":"2025-09-11T00:33:48.011Z","repository":{"id":81393551,"uuid":"288032249","full_name":"mafda/regex_101","owner":"mafda","description":"A regular expression is a sequence of characters that define a search pattern.","archived":false,"fork":false,"pushed_at":"2021-05-28T15:23:37.000Z","size":109,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T20:14:26.847Z","etag":null,"topics":["python3","regex","regular-expression"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mafda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-16T22:08:08.000Z","updated_at":"2022-08-14T04:44:38.000Z","dependencies_parsed_at":"2023-03-03T02:46:24.474Z","dependency_job_id":null,"html_url":"https://github.com/mafda/regex_101","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mafda/regex_101","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafda%2Fregex_101","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafda%2Fregex_101/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafda%2Fregex_101/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafda%2Fregex_101/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mafda","download_url":"https://codeload.github.com/mafda/regex_101/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mafda%2Fregex_101/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274555612,"owners_count":25307444,"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","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["python3","regex","regular-expression"],"created_at":"2024-11-16T12:12:46.698Z","updated_at":"2025-09-11T00:33:47.960Z","avatar_url":"https://github.com/mafda.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Regex (Regular Expression) 101\n\nA Regex or Regular Expression is a sequence of characters that define a search pattern.\n\n## Hackerrank Regex Challenges\n\nSolutions to [Hackerrank's Regular Expression Challenges](https://www.hackerrank.com/domains/regex/)\n\n## Introduction\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n| dot   | The dot (.) matches anything (except for a newline). | [01_matching_anything_but_a_newline.py](https://github.com/mafda/regex_101/blob/master/example/01_matching_anything_but_a_newline.py) |\n| \\d    | The expression \\d matches any digit [0-9]. |  |\n| \\D    | The expression \\D matches any character that is not a digit. | [02_matching_digits_and_non_digit_characters.py](https://github.com/mafda/regex_101/blob/master/example/02_matching_digits_and_non_digit_characters.py) |\n| \\s    | The expression \\s matches any whitespace character [ \\r\\n\\t\\f ]. |  |\n| \\S    | The expression \\S matches any non-white space character | [03_matching_whitespace_and_non_whitespace_character.py](https://github.com/mafda/regex_101/blob/master/example/03_matching_whitespace_and_non_whitespace_character.py) |\n| \\w    | The expression \\w will match any word character. Word characters include alphanumeric characters (a-z, A-Z and 0-9) and underscores (_). |  |\n| \\W    | The expression \\W matches any non-word character. Non-word characters include alphanumeric characters (a-z, A-Z and 0-9) and underscores (_).| [04_matching_world_and_non_world_character.py](https://github.com/mafda/regex_101/blob/master/example/04_matching_world_and_non_world_character.py) |\n| ^    | The ^ symbol matches the position at the start of a string. |  |\n| $    | The $ symbol matches the position at the end of a string. | [05_matching_start_and_end.py](https://github.com/mafda/regex_101/blob/master/example/05_matching_start_and_end.py) |\n\n## Character Class\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n| [ ]   | The character class [ ] matches only one out of several characters placed inside the square brackets. | [06_matching_specific_characters.py](https://github.com/mafda/regex_101/blob/master/example/06_matching_specific_characters.py) |\n| [^]   | The negated character class [^] matches any character that is not in the square brackets. | [07_excluding_specific_characters.py](https://github.com/mafda/regex_101/blob/master/example/07_excluding_specific_characters.py) |\n| -   | A hyphen (-) inside a character class specifies a range of characters where the left and right operands are the respective lower and upper bounds of the range. | [08_matching_character_ranges.py](https://github.com/mafda/regex_101/blob/master/example/08_matching_character_ranges.py) |\n\n## Repetitions\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n| {x} | The tool {x} will match exactly  repetitions of character/character class/groups. | [09_matching_x_repetitions.py](https://github.com/mafda/regex_101/blob/master/example/09_matching_x_repetitions.py) |\n| {x,y} | The {x,y} tool will match between x and y (both inclusive) repetitions of character/character class/group. | [010_matching_xy_repetitions.py](https://github.com/mafda/regex_101/blob/master/example/010_matching_xy_repetitions.py) |\n| * | The * tool will match zero or more repetitions of character/character class/group. | [011_matching_zero_or_more_repetitions.py](https://github.com/mafda/regex_101/blob/master/example/011_matching_zero_or_more_repetitions.py) |\n| + | The + tool will match one or more repetitions of character/character class/group. | [012_matching_one_or_more_repetitions.py](https://github.com/mafda/regex_101/blob/master/example/012_matching_one_or_more_repetitions.py) |\n| $ | The $ boundary matcher matches an occurrence of a character/character class/group at the end of a line. | [013_matching_ending_items.py](https://github.com/mafda/regex_101/blob/master/example/013_matching_ending_items.py) |\n\n## Grouping and Capturing\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n|   \\b  | \\b assert position at a word boundary. Three different positions qualify for word boundaries : Before the first character in the string, if the first character is a word character. Between two characters in the string, where one is a word character and the other is not a word character. After the last character in the string, if the last character is a word character. | [014_matching_word_boundaries.py](https://github.com/mafda/regex_101/blob/master/example/014_matching_word_boundaries.py) |\n|   ()  | Parenthesis ( ) around a regular expression can group that part of regex together. This allows us to apply different quantifiers to that group. These parenthesis also create a numbered capturing. It stores the part of string matched by the part of regex inside parentheses. These numbered capturing can be used for backreferences. ( We shall learn about it later ) | [015_capturing_and_noncapturing_groups.py](https://github.com/mafda/regex_101/blob/master/example/015_capturing_and_noncapturing_groups.py) |\n|   \\|  | Alternations, denoted by the \\| character, match a single item out of several possible items separated by the vertical bar. When used inside a character class, it will match characters; when used inside a group, it will match entire expressions (i.e., everything to the left or everything to the right of the vertical bar). We must use parentheses to limit the use of alternations. | [016_alternative_matching.py](https://github.com/mafda/regex_101/blob/master/example/016_alternative_matching.py) |\n\n## Backreferences\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n| \\group_number  | This tool (\\1 references the first capturing group) matches the same text as previously matched by the capturing group. | [017_matching_same_text_again_and_again.py](https://github.com/mafda/regex_101/blob/master/example/017_matching_same_text_again_and_again.py) |\n| (b)?o\\1  | Backreference to a capturing group that match nothing is different from backreference to a capturing group that did not participate in the match at all. | [018_backreferences_to_failed_groups.py](https://github.com/mafda/regex_101/blob/master/example/018_backreferences_to_failed_groups.py) |\n| (?\\|regex)  | A branch reset group consists of alternations and capturing groups. (?\\|(regex1)\\|(regex2)) Alternatives in branch reset group share same capturing group. Branch reset group is supported by Perl, PHP, Delphi and R. | [019_branch_reset_groups.php](https://github.com/mafda/regex_101/blob/master/example/019_branch_reset_groups.php) |\n\n## Assertions\n\n| Regex | Description | Example |\n| :---: | :---------- | :------ |\n| regex_1(?=regex_2)  | The positive lookahead (?=) asserts regex_1 to be immediately followed by regex_2. The lookahead is excluded from the match. It does not return matches of regex_2. The lookahead only asserts whether a match is possible or not. | [020_positive_lookahead.py](https://github.com/mafda/regex_101/blob/master/example/020_positive_lookahead.py) |\n| regex_1(?!regex_2)  | The negative lookahead (?!) asserts regex_1 not to be immediately followed by regex_2. Lookahead is excluded from the match (do not consume matches of regex_2), but only assert whether a match is possible or not. | [021_negative_lookahead.py](https://github.com/mafda/regex_101/blob/master/example/021_negative_lookahead.py) |\n| (?\u003c=regex_2)regex_1 | The positive lookbehind (?\u003c=) asserts regex_1 to be immediately preceded by regex_2. Lookbehind is excluded from the match (do not consume matches of regex_2), but only assert whether a match is possible or not. | [022_positive_lookbehind.py](https://github.com/mafda/regex_101/blob/master/example/022_positive_lookbehind.py) |\n| (?\u003c!regex_2)regex_1 | The negative lookbehind (?\u003c!) asserts regex_1 not to be immediately preceded by regex_2. Lookbehind is excluded from the match (do not consume matches of regex_2), but only assert whether a match is possible or not. | [023_negative_lookbehind.py](https://github.com/mafda/regex_101/blob/master/example/023_negative_lookbehind.py) |\n\n## Applications\n\n| Problem | Solution |\n| :-----: | :------: |\n| Find A Sub-Word | [024_find-a-sub-word.py](https://github.com/mafda/regex_101/blob/master/example/024_find-a-sub-word.py) |\n| Alien Username | [025_alien_username.py](https://github.com/mafda/regex_101/blob/master/example/025_alien_username.py) |\n| Find a Word | [026_find_a_word.py](https://github.com/mafda/regex_101/blob/master/example/026_find_a_word.py) |\n\n\n---\n\nmade with 💙 by [mafda](https://mafda.github.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmafda%2Fregex_101","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmafda%2Fregex_101","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmafda%2Fregex_101/lists"}