Tutorial


Preface

Human2Regex (H2R) is a way to spell out a regular expression in an easy to read, easy to modify language. H2R supports multiple languages as well as many (though not all) different regular expression types such as named groups and quantifiers. You may notice multiple keywords specifying the same thing, and that is intended! H2R is made to be flexible and easy to understand. With a range, do you prefer "...", "through", or "to"? It's up to you to choose, H2R supports all of those!

Matching

Match using the keyword "match" followed by what you want to match. Example: match "hello world" will generate a regex that matches "hello world". You can chain multiple matches with the keyword "then", or use a newline and another match statement. Example: match "hello" then " world". Matches that have a few possibilities can be matched with "or". Example: match "hello world" or "hello" will match either of those two. Matches which are optional can be done using the keyword "optional(ly)". Example: optionally match "world". Anything inside the quoted string will be escaped to become a valid regular expression. H2R also comes with some convenience keywords "word(s)", "digit(s)", "character(s)", "whitespace(s)", and "number(s)" to capture words, single digits, characters, whitespace, and multiple digits respectively. Example: match a word. H2R can also capture a range of characters with the keywords from/to or between/and. Examples: match from "a" to "z" then between "a" to "z"

Repetition

H2R supports 2 types of repetition: single match repetition, or grouped repetition. When using "match" you can specify the number of captures you want just before the text you want to capture. Example: match 2 digits will match any 2 characters in a row. You can also specify a range you wish to capture. Example: match 2..5 digits will match 2, 3, 4, or 5 digits. You can specify if the final number is exclusive with the "exclusive" keyword. Example: match 2 to 5 exclusive digits will only match up to 4 digits. You can group a repetition using the "repeat" keyword. By default, this will match 0 or more of the following statements. The same qualifiers that exist for match exist for repeat. Example: optionally repeat 3...7 times

Grouping

Groups in H2R are created using the "create a group" phrase. With groups, you can specify if it is optional with the "optional" keyword, or if it has a name with "called" or "named". Example: create an optional group called "MyGroup"