mirror of
https://github.com/pdemian/human2regex.git
synced 2025-05-16 12:30:09 -07:00
1 line
4.4 KiB
HTML
1 line
4.4 KiB
HTML
<!DOCTYPE html><html lang="en" dir="ltr"><head><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content="Create regular expressions with natural, human language"><meta name="keywords" content="Human2Regex, Human, Regex, Natural, Language, Natural Language"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Human2Regex Tutorial</title><link href="bundle.min.css" rel="stylesheet" type="text/css"><meta name="theme-color" content="#212529"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="default"><link rel="icon" type="image/x-icon" href="favicon.ico"></head><body><a class="skip skip-top" href="#maincontent">Skip to main content</a><div class="wrapper"><nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav"><div class="container"><a class="navbar-brand" href="index.html"><img src="favicon.png" width="30" height="30" class="d-inline-block align-top" alt="logo"> Human2Regex</a></div></nav><div class="container" id="maincontent" role="main"><div id="tutorial"><h2>Tutorial</h2><br><p class="font-weight-bold">Preface</p><p>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!</p><p class="font-weight-bold">Matching</p><p>Match using the keyword "match" followed by what you want to match. Example: <code class="cm-s-idea">match "hello world"</code> 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: <code class="cm-s-idea">match "hello" then " world"</code>. Matches that have a few possibilities can be matched with "or". Example: <code class="cm-s-idea">match "hello world" or "hello"</code> will match either of those two. Matches which are optional can be done using the keyword "optional(ly)". Example: <code class="cm-s-idea">optionally match "world"</code>. 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: <code class="cm-s-idea">match a word</code>. H2R can also capture a range of characters with the keywords from/to or between/and. Examples: <code class="cm-s-idea">match from "a" to "z" then between "a" to "z"</code></p><p class="font-weight-bold">Repetition</p><p>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: <code class="cm-s-idea">match 2 digits</code> will match any 2 characters in a row. You can also specify a range you wish to capture. Example: <code class="cm-s-idea">match 2..5 digits</code> will match 2, 3, 4, or 5 digits. You can specify if the final number is exclusive with the "exclusive" keyword. Example: <code class="cm-s-idea">match 2 to 5 exclusive digits</code> 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: <code class="cm-s-idea">optionally repeat 3...7 times</code></p><p class="font-weight-bold">Grouping</p><p>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: <code class="cm-s-idea">create an optional group called "MyGroup"</code></p></div></div><footer><div class="container"><div class="row"><div class="col-lg-8 col-md-10 mx-auto"><p class="copyright">Copyright © 2020 Patrick Demian. This page's source code is available at <a rel="noopener noreferrer" href="https://github.com/pdemian/human2regex">github.com/pdemian/human2regex</a></p></div></div></div></footer></div><script defer="defer" src="bundle.min.js"></script></body></html> |