1
0
mirror of https://github.com/pdemian/human2regex.git synced 2025-05-16 04:20:35 -07:00

Initial ssg change

This commit is contained in:
Patrick Demian 2021-01-15 04:54:08 -05:00
parent 5767619463
commit fb436be143
32 changed files with 1312 additions and 3798 deletions

View File

@ -1 +1 @@
<!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="Not Found"><meta name="keywords" content="Human2Regex, Human, Regex, Natural, Language, Natural Language"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Error 404 - Not Found</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-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex</a><div class="float-right heading-links"><a class="heading-link" href="index.html">Index</a> <span>&nbsp;|&nbsp;</span> <a class="heading-link" href="tutorial.html">Tutorial</a></div></div></nav><div class="container contained-container" id="maincontent" role="main"><div class="align_header"><div class="mx-auto"><div class="site-heading"><h1>404</h1><span class="subheading">Not Found</span></div></div></div><br><br><br><div class="row"><div class="col-12 mx-auto"><h3 class="align_header">The resource could not be found.</h3></div></div></div><footer><div class="container"><div class="row"><div class="col-lg-8 col-md-10 mx-auto"><p class="copyright">Copyright &copy; 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>
<!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="Not Found"><meta name="keywords" content="Human2Regex, Human, Regex, Natural, Language, Natural Language"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Error 404 - Not Found</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-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex</a><div class="float-right heading-links"><a class="heading-link" href="/index.html">Index</a> <span>&nbsp;|&nbsp;</span> <a class="heading-link" href="/tutorial.html">Tutorial</a></div></div></nav><div class="container contained-container" id="maincontent" role="main"><div class="align_header"><div class="mx-auto"><div class="site-heading"><h1>404</h1><span class="subheading">Not Found</span></div></div></div><br><br><br><div class="row"><div class="col-12 mx-auto"><h3 class="align_header">The resource could not be found.</h3></div></div></div><footer><div class="container"><div class="row"><div class="col-lg-8 col-md-10 mx-auto"><p class="copyright">Copyright &copy; 2021 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>

2
docs/bundle.min.css vendored

File diff suppressed because one or more lines are too long

14
docs/bundle.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,4 @@
<!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</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-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex</a><div class="float-right heading-links"><a class="heading-link" href="index.html">Index</a> <span>&nbsp;|&nbsp;</span> <a class="heading-link" href="tutorial.html">Tutorial</a></div></div></nav><div class="container" id="maincontent" role="main"><div class="row"><div class="col-lg-8 tenpx-margin-bottom"><div class="form-group row zero-margin-bottom"><label for="dialect" class="col-sm-4 col-form-label">Regex dialect:</label><div class="col-sm-8"><select class="form-control" id="dialect"><option value="js" selected="selected">Javascript</option><option value="dotnet">.NET</option><option value="python">Python</option><option value="boost">C++ Boost</option><option value="java">Java 7+</option><option value="pcre">PCRE</option></select></div></div><h4>Your Regular Expression:</h4><div class="row"><div class="col-xl-11 tenpx-margin-bottom"><input readonly="readonly" class="form-control" id="regex"></div><div class="col-xl-1"><button type="button" class="btn btn-secondary float-right" id="clip">Copy</button></div></div><h4>Human Speak:</h4><textarea class="form-control" id="human" rows="25">
/* Make a regex that matches (basic) URLs */
<!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</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-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex</a><div class="float-right heading-links"><a class="heading-link" href="/index.html">Index</a> <span>&nbsp;|&nbsp;</span> <a class="heading-link" href="/tutorial.html">Tutorial</a></div></div></nav><div class="container" id="maincontent" role="main"><div class="row"><div class="col-lg-8 tenpx-margin-bottom"><div class="form-group row zero-margin-bottom"><label for="dialect" class="col-sm-4 col-form-label">Regex dialect:</label><div class="col-sm-8"><select class="form-control" id="dialect"><option value="js" selected="selected">Javascript</option><option value="dotnet">.NET</option><option value="python">Python</option><option value="boost">C++ Boost</option><option value="java">Java 7+</option><option value="pcre">PCRE</option></select></div></div><h4>Your Regular Expression:</h4><div class="row"><div class="col-xl-11 tenpx-margin-bottom"><input readonly="readonly" class="form-control" id="regex"></div><div class="col-xl-1"><button type="button" class="btn btn-secondary float-right" id="clip">Copy</button></div></div><h4>Human Speak:</h4><textarea class="form-control" id="human" rows="25">/* Make a regex that matches (basic) URLs */
using global and exact matching
create an optional group called protocol
@ -30,5 +29,4 @@ create an optional group
create an optional group
# fragment, again, we don't care, so ignore everything afterwards
match "#"
match 0+ any thing
</textarea><h4>Errors:</h4><textarea readonly="readonly" class="form-control" id="errors" rows="5"></textarea></div><br><div class="col-lg-4 tenpx-margin-bottom"><div class="cheatsheet"><h2>Cheat Sheet:</h2><p>Full documentation available <a href="tutorial.html">here</a></p><p class="font-weight-bold">Matching</p><p><code class="cm-s-idea">match "hello world"</code> matches "hello world" exactly</p><p></p><p><code class="cm-s-idea">match "hello" then optionally " world"</code> matches "hello" or "hello world"</p><p><code class="cm-s-idea">match "hello" or "world"</code> matches "hello" or "world</p><p><code class="cm-s-idea">match a word</code> matches any word</p><p class="font-weight-bold">Repetition</p><p><code class="cm-s-idea">match 0+ "hello"</code> matches 0 or more "hello"s</p><p><code class="cm-s-idea">match 3 "hello"</code> matches exactly "hellohellohello"</p><p><code class="cm-s-idea">match 1 to 5 "hello"</code> matches between 1 to 5 "hello"s</p><p><code class="cm-s-idea">repeat 0 or more</code> repeats the intended text 0 or more times (default)</p><p><code class="cm-s-idea">optionally repeat between 3 to 5</code> optionally repeats the indented text 3 to 5 times</p><p class="font-weight-bold">Grouping</p><p><code class="cm-s-idea">create a group called mygroup</code> creates a group called "mygroup"</p><p><code class="cm-s-idea">create an optional group</code> creates an unnamed optional group</p><p class="font-weight-bold">Using</p><p><code class="cm-s-idea">using global and case insensitive</code> uses the 'g' and 'i' flags</p><p class="font-weight-bold">Misc</p><p><code class="cm-s-idea">// comment</code> is a single line comment</p><p><code class="cm-s-idea">/* comment */</code> is a multi line comment</p></div></div></div></div><footer><div class="container"><div class="row"><div class="col-lg-8 col-md-10 mx-auto"><p class="copyright">Copyright &copy; 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>
match 0+ any thing</textarea><h4>Errors:</h4><textarea readonly="readonly" class="form-control" id="errors" rows="5"></textarea></div><br><div class="col-lg-4 tenpx-margin-bottom"><div class="cheatsheet"><h2>Cheat Sheet:</h2><p>Full documentation available <a href="/tutorial.html">here</a></p><p class="font-weight-bold">Matching</p><p><code class="cm-s-idea">match "hello world"</code> matches "hello world" exactly</p><p></p><p><code class="cm-s-idea">match "hello" then optionally " world"</code> matches "hello" or "hello world"</p><p><code class="cm-s-idea">match "hello" or "world"</code> matches "hello" or "world</p><p><code class="cm-s-idea">match a word</code> matches any word</p><p class="font-weight-bold">Repetition</p><p><code class="cm-s-idea">match 0+ "hello"</code> matches 0 or more "hello"s</p><p><code class="cm-s-idea">match 3 "hello"</code> matches exactly "hellohellohello"</p><p><code class="cm-s-idea">match 1 to 5 "hello"</code> matches between 1 to 5 "hello"s</p><p><code class="cm-s-idea">repeat 0 or more</code> repeats the intended text 0 or more times (default)</p><p><code class="cm-s-idea">optionally repeat between 3 to 5</code> optionally repeats the indented text 3 to 5 times</p><p class="font-weight-bold">Grouping</p><p><code class="cm-s-idea">create a group called mygroup</code> creates a group called "mygroup"</p><p><code class="cm-s-idea">create an optional group</code> creates an unnamed optional group</p><p class="font-weight-bold">Using</p><p><code class="cm-s-idea">using global and case insensitive</code> uses the 'g' and 'i' flags</p><p class="font-weight-bold">Misc</p><p><code class="cm-s-idea">// comment</code> is a single line comment</p><p><code class="cm-s-idea">/* comment */</code> is a multi line comment</p></div></div></div></div><footer><div class="container"><div class="row"><div class="col-lg-8 col-md-10 mx-auto"><p class="copyright">Copyright &copy; 2021 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>

File diff suppressed because one or more lines are too long

2
lib/generator.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
import { IToken } from "chevrotain";
/**
* List of regular expression dialects we support

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegularExpressionCST = exports.IfIdentStatementCST = exports.IfPatternStatementCST = exports.BackrefStatementCST = exports.GroupStatementCST = exports.RepeatStatementCST = exports.MatchStatementCST = exports.CountSubStatementCST = exports.UsingStatementCST = exports.MatchSubStatementCST = exports.StatementCST = exports.MatchStatementValue = exports.MatchSubStatementValue = exports.MatchSubStatementType = exports.UsingFlags = exports.H2RCST = exports.GeneratorContext = exports.RegexDialect = void 0;
/**

View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/**
* Minimizes the match string by finding duplicates or substrings in the array
*

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.dontClobberRepetition = exports.groupIfRequired = exports.minimizeMatchString = void 0;
/**

2
lib/index.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/**
* Includes all packages
* @packageDocumentation

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegexDialect = exports.ParseResult = exports.Human2RegexParser = exports.Human2RegexParserOptions = exports.TokenizeResult = exports.IndentType = exports.Human2RegexLexer = exports.Human2RegexLexerOptions = exports.CommonError = void 0;
/**

2
lib/lexer.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/**
* The Lexer for Human2Regex
* @packageDocumentation

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Human2RegexLexer = exports.TokenizeResult = exports.Human2RegexLexerOptions = exports.IndentType = void 0;
/**

2
lib/parser.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/**
* The parser for Human2Regex
* @packageDocumentation

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });

2
lib/tokens.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/** @internal */ export declare const Zero: import("chevrotain").TokenType;
/** @internal */ export declare const One: import("chevrotain").TokenType;
/** @internal */ export declare const Two: import("chevrotain").TokenType;

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CaseInsensitive = exports.CarriageReturn = exports.Newline = exports.Repeat = exports.Called = exports.Create = exports.To = exports.From = exports.Exclusive = exports.Inclusive = exports.Exactly = exports.Times = exports.A = exports.Group = exports.Linefeed = exports.Tab = exports.Between = exports.Not = exports.Matching = exports.Exact = exports.Multiline = exports.Global = exports.Using = exports.Unicode = exports.Number = exports.Boundary = exports.Whitespace = exports.Integer = exports.Decimal = exports.Letter = exports.Character = exports.Digit = exports.Word = exports.And = exports.Or = exports.Anything = exports.Then = exports.Match = exports.Optional = exports.Ten = exports.Nine = exports.Eight = exports.Seven = exports.Six = exports.Five = exports.Four = exports.Three = exports.Two = exports.One = exports.Zero = void 0;
exports.AllTokens = exports.Outdent = exports.Indent = exports.StringLiteral = exports.NumberLiteral = exports.Identifier = exports.MultilineComment = exports.SingleLineComment = exports.WS = exports.EndOfLine = exports.Else = exports.If = exports.The = exports.Call = exports.OrMore = exports.CaseSensitive = void 0;

2
lib/utilities.d.ts vendored
View File

@ -1,4 +1,4 @@
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
/**
* Some utility functions for Human2Regex
* @packageDocumentation

View File

@ -1,5 +1,5 @@
"use strict";
/*! Copyright (c) 2020 Patrick Demian; Licensed under MIT */
/*! Copyright (c) 2021 Patrick Demian; Licensed under MIT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonError = exports.append = exports.regexEscape = exports.removeQuotes = exports.findLastIndex = exports.last = exports.first = exports.isSingleRegexCharacter = exports.combineFlags = exports.hasFlag = exports.makeFlag = exports.usefulConditional = exports.unusedParameter = void 0;
/**

4431
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,6 @@
"@types/glob": "^7.1.3",
"@types/html-minifier": "^3.5.3",
"@types/jest": "^26.0.19",
"@types/mustache": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"before-build-webpack": "^0.2.9",
@ -17,10 +16,10 @@
"css-loader": "^4.3.0",
"eslint": "^7.17.0",
"glob": "^7.1.6",
"handlebars": "^4.7.6",
"html-minifier": "^4.0.0",
"jest": "^26.6.3",
"mini-css-extract-plugin": "^1.3.3",
"mustache": "^4.1.0",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"remove-files-webpack-plugin": "^1.4.4",
"ts-jest": "^26.4.4",

View File

@ -1,21 +1,21 @@
{{! Copyright (c) 2021 Patrick Demian; Licensed under MIT }}
{{> header}}
{{> header title="Error 404 - Not Found" description="Not Found"}}
<!-- Main Content -->
<div class="container contained-container" id="maincontent" role="main">
<!-- Page Header -->
<div class="align_header">
<div class="mx-auto">
<div class="site-heading">
<h1>{{error-code}}</h1>
<span class="subheading">{{error-subheading}}</span>
<h1>404</h1>
<span class="subheading">Not Found</span>
</div>
</div>
</div>
<br><br><br>
<div class="row">
<div class="col-12 mx-auto">
<h3 class="align_header">{{{error-string}}}</h3>
<h3 class="align_header">The resource could not be found.</h3>
</div>
</div>
</div>

View File

@ -1,9 +0,0 @@
{
"page": {
"title": "Error 404 - Not Found",
"description": "Not Found"
},
"error-code": "404",
"error-subheading": "Not Found",
"error-string": "The resource could not be found."
}

32
src/docs/example_code.hbs Normal file
View File

@ -0,0 +1,32 @@
/* Make a regex that matches (basic) URLs */
using global and exact matching
create an optional group called protocol
match "http"
possibly match "s"
match "://"
create an optional group called subdomain
repeat
match a word, then "."
create a group called domain
match 1+ words or "_" or "-"
match "."
match a word
# port, but we don't care about it, so ignore it
optionally match ":" then 0+ digits
create an optional group called path
repeat
match "/"
match 0+ words or "_" or "-"
create an optional group
# we don't want to capture the '?', so don't name the group until afterwards
match "?"
create a group called query
repeat
match 1+ words or "_" or "-"
match "="
match 1+ words or "_" or "-"
create an optional group
# fragment, again, we don't care, so ignore everything afterwards
match "#"
match 0+ any thing

View File

@ -14,7 +14,7 @@
</div>
<!-- Our script -->
<script defer src="bundle.min.js"></script>
<script defer src="/bundle.min.js"></script>
</body>
</html>

View File

@ -4,19 +4,19 @@
<head>
<!-- Metadata -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="{{page.description}}">
<meta name="description" content="{{description}}">
<meta name="keywords" content="Human2Regex, Human, Regex, Natural, Language, Natural Language">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{{page.title}}</title>
<title>{{title}}</title>
<!-- Our own CSS -->
<link href="bundle.min.css" rel="stylesheet" type="text/css">
<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">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
</head>
<body>
<a class="skip skip-top" href="#maincontent">Skip to main content</a>
@ -25,14 +25,14 @@
<!-- Navigation -->
<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-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex
<a class="navbar-brand" href="/index.html">
<img src="/favicon-small.png" width="30" height="30" class="d-inline-block align-top" alt="logo">&nbsp;Human2Regex
</a>
<div class="float-right heading-links">
<a class="heading-link" href="index.html">Index</a>
<a class="heading-link" href="/index.html">Index</a>
<span>&nbsp;|&nbsp;</span>
<a class="heading-link" href="tutorial.html">Tutorial</a>
<a class="heading-link" href="/tutorial.html">Tutorial</a>
</div>
</div>
</nav>

64
src/docs/index.hbs Normal file
View File

@ -0,0 +1,64 @@
{{! Copyright (c) 2021 Patrick Demian; Licensed under MIT }}
{{> header title="Human2Regex" description="Create regular expressions with natural, human language"}}
<!-- Main Content -->
<div class="container" id="maincontent" role="main">
<div class="row">
<div class="col-lg-8 tenpx-margin-bottom">
<div class="form-group row zero-margin-bottom">
<label for="dialect" class="col-sm-4 col-form-label">Regex dialect:</label>
<div class="col-sm-8">
<select class="form-control" id="dialect">
<option value="js" selected>Javascript</option>
<option value="dotnet">.NET</option>
<option value="python">Python</option>
<option value="boost">C++ Boost</option>
<option value="java">Java 7+</option>
<option value="pcre">PCRE</option>
</select>
</div>
</div>
<h4>Your Regular Expression:</h4>
<div class="row">
<div class="col-xl-11 tenpx-margin-bottom">
<input readonly type="text" class="form-control" id="regex"></input>
</div>
<div class="col-xl-1">
<button type="button" class="btn btn-secondary float-right" id="clip">Copy</button>
</div>
</div>
<h4>Human Speak:</h4>
<textarea class="form-control" id="human" rows="25">{{> example_code}}</textarea>
<h4>Errors:</h4>
<textarea readonly class="form-control " id="errors" rows="5"></textarea>
</div>
<br>
<div class="col-lg-4 tenpx-margin-bottom">
<div class="cheatsheet">
<h2>Cheat Sheet:</h2>
<p>Full documentation available <a href="/tutorial.html">here</a></p>
<p class="font-weight-bold">Matching</p>
<p>{{i-code}}match "hello world"{{end-i-code}} matches "hello world" exactly<p>
<p>{{i-code}}match "hello" then optionally " world"{{end-i-code}} matches "hello" or "hello world"</p>
<p>{{i-code}}match "hello" or "world"{{end-i-code}} matches "hello" or "world</p>
<p>{{i-code}}match a word{{end-i-code}} matches any word
<p class="font-weight-bold">Repetition</p>
<p>{{i-code}}match 0+ "hello"{{end-i-code}} matches 0 or more "hello"s</p>
<p>{{i-code}}match 3 "hello"{{end-i-code}} matches exactly "hellohellohello"</p>
<p>{{i-code}}match 1 to 5 "hello"{{end-i-code}} matches between 1 to 5 "hello"s</p>
<p>{{i-code}}repeat 0 or more{{end-i-code}} repeats the intended text 0 or more times (default)</p>
<p>{{i-code}}optionally repeat between 3 to 5{{end-i-code}} optionally repeats the indented text 3 to 5 times</p>
<p class="font-weight-bold">Grouping</p>
<p>{{i-code}}create a group called mygroup{{end-i-code}} creates a group called "mygroup"</p>
<p>{{i-code}}create an optional group{{end-i-code}} creates an unnamed optional group</p>
<p class="font-weight-bold">Using</p>
<p>{{i-code}}using global and case insensitive{{end-i-code}} uses the 'g' and 'i' flags</p>
<p class="font-weight-bold">Misc</p>
<p>{{i-code}}// comment{{end-i-code}} is a single line comment</p>
<p>{{i-code}}/* comment */{{end-i-code}} is a multi line comment</p>
</div>
</div>
</div>
</div>
{{> footer}}

View File

@ -1,6 +0,0 @@
{
"page": {
"title": "Human2Regex",
"description": "Create regular expressions with natural, human language"
}
}

View File

@ -1,97 +0,0 @@
{{! Copyright (c) 2021 Patrick Demian; Licensed under MIT }}
{{> header}}
<!-- Main Content -->
<div class="container" id="maincontent" role="main">
<div class="row">
<div class="col-lg-8 tenpx-margin-bottom">
<div class="form-group row zero-margin-bottom">
<label for="dialect" class="col-sm-4 col-form-label">Regex dialect:</label>
<div class="col-sm-8">
<select class="form-control" id="dialect">
<option value="js" selected>Javascript</option>
<option value="dotnet">.NET</option>
<option value="python">Python</option>
<option value="boost">C++ Boost</option>
<option value="java">Java 7+</option>
<option value="pcre">PCRE</option>
</select>
</div>
</div>
<h4>Your Regular Expression:</h4>
<div class="row">
<div class="col-xl-11 tenpx-margin-bottom">
<input readonly type="text" class="form-control" id="regex"></input>
</div>
<div class="col-xl-1">
<button type="button" class="btn btn-secondary float-right" id="clip">Copy</button>
</div>
</div>
<h4>Human Speak:</h4>
<textarea class="form-control" id="human" rows="25">
/* Make a regex that matches (basic) URLs */
using global and exact matching
create an optional group called protocol
match "http"
possibly match "s"
match "://"
create an optional group called subdomain
repeat
match a word, then "."
create a group called domain
match 1+ words or "_" or "-"
match "."
match a word
# port, but we don't care about it, so ignore it
optionally match ":" then 0+ digits
create an optional group called path
repeat
match "/"
match 0+ words or "_" or "-"
create an optional group
# we don't want to capture the '?', so don't name the group until afterwards
match "?"
create a group called query
repeat
match 1+ words or "_" or "-"
match "="
match 1+ words or "_" or "-"
create an optional group
# fragment, again, we don't care, so ignore everything afterwards
match "#"
match 0+ any thing
</textarea>
<h4>Errors:</h4>
<textarea readonly class="form-control " id="errors" rows="5"></textarea>
</div>
<br>
<div class="col-lg-4 tenpx-margin-bottom">
<div class="cheatsheet">
<h2>Cheat Sheet:</h2>
<p>Full documentation available <a href="tutorial.html">here</a></p>
<p class="font-weight-bold">Matching</p>
<p><code class="cm-s-idea">match "hello world"</code> matches "hello world" exactly<p>
<p><code class="cm-s-idea">match "hello" then optionally " world"</code> matches "hello" or "hello world"</p>
<p><code class="cm-s-idea">match "hello" or "world"</code> matches "hello" or "world</p>
<p><code class="cm-s-idea">match a word</code> matches any word
<p class="font-weight-bold">Repetition</p>
<p><code class="cm-s-idea">match 0+ "hello"</code> matches 0 or more "hello"s</p>
<p><code class="cm-s-idea">match 3 "hello"</code> matches exactly "hellohellohello"</p>
<p><code class="cm-s-idea">match 1 to 5 "hello"</code> matches between 1 to 5 "hello"s</p>
<p><code class="cm-s-idea">repeat 0 or more</code> repeats the intended text 0 or more times (default)</p>
<p><code class="cm-s-idea">optionally repeat between 3 to 5</code> optionally repeats the indented text 3 to 5 times</p>
<p class="font-weight-bold">Grouping</p>
<p><code class="cm-s-idea">create a group called mygroup</code> creates a group called "mygroup"</p>
<p><code class="cm-s-idea">create an optional group</code> creates an unnamed optional group</p>
<p class="font-weight-bold">Using</p>
<p><code class="cm-s-idea">using global and case insensitive</code> uses the 'g' and 'i' flags</p>
<p class="font-weight-bold">Misc</p>
<p><code class="cm-s-idea">// comment</code> is a single line comment</p>
<p><code class="cm-s-idea">/* comment */</code> is a multi line comment</p>
</div>
</div>
</div>
</div>
{{> footer}}

View File

@ -1,6 +1,6 @@
{{! Copyright (c) 2021 Patrick Demian; Licensed under MIT }}
{{> header}}
{{> header title="Human2Regex Tutorial" description="Create regular expressions with natural, human language"}}
<!-- Main Content -->
<div class="container contained-container" id="maincontent" role="main">
<div id="tutorial">
@ -12,32 +12,31 @@
<br>
<p class="font-weight-bold" id="tut-first-match">1. Your first Match</p>
<p>Every language starts with a "Hello World" program, so let's match the output of those programs. Matching is done using the keyword <code class="cm-s-idea">match</code> followed by what you want to match.
<span class="tutorial-code"><code class="cm-s-idea">
<p>Every language starts with a "Hello World" program, so let's match the output of those programs. Matching is done using the keyword {{i-code}}match{{end-i-code}} followed by what you want to match.
{{s-code}}
match "Hello World"
</code></span>
The above statement will generate a regular expression that matches "Hello World", like "/Hello World/". Any invalid characters will automatically be escaped, so you don't need to worry about it. H2R also supports block comments with <code class="cm-s-idea">/**/</code>, or line comments with <code class="cm-s-idea">//</code> or <code class="cm-s-idea">#</code> so you can explain why or what you intend to match.</p>
<pre class="tutorial-code"><code class="cm-s-idea">/* This is a block comment */
{{end-s-code}}
The above statement will generate a regular expression that matches "Hello World", like "/Hello World/". Any invalid characters will automatically be escaped, so you don't need to worry about it. H2R also supports block comments with {{i-code}}/**/{{end-i-code}}, or line comments with {{i-code}}//{{end-i-code}} or {{i-code}}#{{end-i-code}} so you can explain why or what you intend to match.</p>
{{p-code}}/* This is a block comment */
match "Hello World" // matches the output of "Hello World" programs
</code></pre>
<p>Now what if we want to match every case variation of "Hello World" like "hello world" or "hELLO wORLD"? H2R supports the <code class="cm-s-idea">or</code> operator which allows you to specify many possible combinations.
<span class="tutorial-code"><code class="cm-s-idea">
{{end-p-code}}
<p>Now what if we want to match every case variation of "Hello World" like "hello world" or "hELLO wORLD"? H2R supports the {{i-code}}or{{end-i-code}} operator which allows you to specify many possible combinations.
{{s-code}}
match "Hello World" or "hello world" or "hELLO wORLD"
</code></span>
Or, you can use a <code class="cm-s-idea">using</code> statement to specify that you want it to be case insensitive.</p>
{{end-s-code}}
Or, you can use a {{i-code}}using{{end-i-code}} statement to specify that you want it to be case insensitive.</p>
<br>
<p class="font-weight-bold" id="tut-using">2. Using Specifiers</p>
<p>Using statements appear at the beginning. You may have one or more using statements which each can contain one or more specifiers. For example:
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
using global and case insensitive matching
</code></span>
{{end-s-code}}
or</p>
<pre class="tutorial-code">
<code class="cm-s-idea">using global
{{p-code}}using global
using case insensitive
</code></pre>
<p>The <code class="cm-s-idea">matching</code> keyword is optional. The flags which are available are:</p>
{{end-p-code}}
<p>The {{i-code}}matching{{end-i-code}} keyword is optional. The flags which are available are:</p>
<table class="table table-sm table-striped table-bordered">
<thead>
@ -49,27 +48,27 @@ using case insensitive
</thead>
<tbody>
<tr>
<td><code class="cm-s-idea">multiline</code></td>
<td>{{i-code}}multiline{{end-i-code}}</td>
<td>Matches can cross line breaks</td>
<td>/&lt;your regex&gt;/m</td>
</tr>
<tr>
<td><code class="cm-s-idea">global</code></td>
<td>{{i-code}}global{{end-i-code}}</td>
<td>Multiple matches are allowed</td>
<td>/&lt;your regex&gt;/g</td>
</tr>
<tr>
<td><code class="cm-s-idea">case sensitive</code></td>
<td>{{i-code}}case sensitive{{end-i-code}}</td>
<td>Match must be exact case</td>
<td><span class="font-italic">none</span></td>
</tr>
<tr>
<td><code class="cm-s-idea">case insensitive</code></td>
<td>{{i-code}}case insensitive{{end-i-code}}</td>
<td>Match may be any case</td>
<td>/&lt;your regex&gt;/i</td>
</tr>
<tr>
<td><code class="cm-s-idea">exact</code></td>
<td>{{i-code}}exact{{end-i-code}}</td>
<td>An exact statement matches a whole line exactly, nothing before, nothing after</td>
<td>/^&lt;your regex&gt;$/</td>
</tr>
@ -77,70 +76,69 @@ using case insensitive
</table>
<p>To match any variation of hello world, we would then do the following:</p>
<pre class="tutorial-code"><code class="cm-s-idea">using case insensitive matching
<pre class="tutorial-code">{{i-code}}using case insensitive matching
match "hello world"
</code></pre>
{{end-p-code}}
<br>
<p class="font-weight-bold" id="tut-multiple-match">3. Matching multiple items</p>
<p>H2R comes with 2 options to match multiple items in a row. The first is to simply write multiple separate <code class="cm-s-idea">match</code> statements like:</p>
<pre class="tutorial-code">
<code class="cm-s-idea">match "hello"
<p>H2R comes with 2 options to match multiple items in a row. The first is to simply write multiple separate {{i-code}}match{{end-i-code}} statements like:</p>
{{p-code}}match "hello"
match " "
match "world"
</code></pre>
<p>However, you can also use a comma, <code class="cm-s-idea">and</code>, or <code class="cm-s-idea">then</code> for a more concise match.
<span class="tutorial-code"><code class="cm-s-idea">
{{end-p-code}}
<p>However, you can also use a comma, {{i-code}}and{{end-i-code}}, or {{i-code}}then{{end-i-code}} for a more concise match.
{{s-code}}
match "hello", " ", "world"
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "hello" and " " and "world"
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "hello" then " " then "world"
</code></span>
{{end-s-code}}
or any combination like
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "hello", " " and then "world"
</code></span>
{{end-s-code}}
<br>
<p class="font-weight-bold" id="tut-optionality">4. Optionality</p>
<p>Sometimes you wish to match something that may or may not exist. In H2R, this is done via the <code class="cm-s-idea">optional</code>, <code class="cm-s-idea">optionally</code>, <code class="cm-s-idea">possibly</code> or <code class="cm-s-idea">maybe</code> keyword.
<span class="tutorial-code"><code class="cm-s-idea">
<p>Sometimes you wish to match something that may or may not exist. In H2R, this is done via the {{i-code}}optional{{end-i-code}}, {{i-code}}optionally{{end-i-code}}, {{i-code}}possibly{{end-i-code}} or {{i-code}}maybe{{end-i-code}} keyword.
{{s-code}}
optionally match "hello world"
</code></span>
will match 0 or 1 "hello world"'s. This can be used alongside matching multiple statements in a single <code class="cm-s-idea">match</code> statement.
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
will match 0 or 1 "hello world"'s. This can be used alongside matching multiple statements in a single {{i-code}}match{{end-i-code}} statement.
{{s-code}}
match "hello", maybe " ", "world"
</code></span>
will match "hello", an optional space if it exists, and "world". However, the start <code class="cm-s-idea">optional</code> is for the entire match statement. Thus,
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
will match "hello", an optional space if it exists, and "world". However, the start {{i-code}}optional{{end-i-code}} is for the entire match statement. Thus,
{{s-code}}
possibly match "hello", " ", then "world"
</code></span>
will actually make the whole "hello world" an optional match rather than just the first "hello". If you want to make the first match optional but keep the rest required, place the <code class="cm-s-idea">optional</code> immediately after the <code class="cm-s-idea">match</code>.</p>
{{end-s-code}}
will actually make the whole "hello world" an optional match rather than just the first "hello". If you want to make the first match optional but keep the rest required, place the {{i-code}}optional{{end-i-code}} immediately after the {{i-code}}match{{end-i-code}}.</p>
<br>
<p class="font-weight-bold" id="tut-negation">5. Negation</p>
<p>You can negate a match with the operator <code class="cm-s-idea">not</code>
<span class="tutorial-code"><code class="cm-s-idea">
<p>You can negate a match with the operator {{i-code}}not{{end-i-code}}
{{s-code}}
match not "hello world"
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match anything but "hello world"
</code></span>
{{end-s-code}}
will match everything except for "hello world".</p>
<br>
<p class="font-weight-bold" id="tut-other-match">6. Other matching specifiers</p>
<p>Many times you don't know exactly what you wish to match. H2R comes with many specifiers that you can use for your matching. For example, you may wish to match any word. You can do that with:
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match a word
</code></span>
The <code class="cm-s-idea">a</code> or <code class="cm-s-idea">an</code> is optional. The possible specifiers that H2R supports are the following:</p>
{{end-s-code}}
The {{i-code}}a{{end-i-code}} or {{i-code}}an{{end-i-code}} is optional. The possible specifiers that H2R supports are the following:</p>
<table class="table table-sm table-striped table-bordered">
<thead>
<tr>
@ -152,71 +150,71 @@ match a word
</thead>
<tbody>
<tr>
<td><code class="cm-s-idea">anything</code></td>
<td>{{i-code}}anything{{end-i-code}}</td>
<td>Matches any character</td>
<td>.</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">word(s)</code></td>
<td>{{i-code}}word(s){{end-i-code}}</td>
<td>Matches many a-z, A-Z, _, or digit characters</td>
<td>\w+</td>
<td>For a-z only, use <code class="cm-s-idea">letter(s)</code></td>
<td>For a-z only, use {{i-code}}letter(s){{end-i-code}}</td>
</tr>
<tr>
<td><code class="cm-s-idea">letter(s)</code></td>
<td>{{i-code}}letter(s){{end-i-code}}</td>
<td>Matches any letter character</td>
<td>[a-zA-Z]</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">number(s)</code></td>
<td>{{i-code}}number(s){{end-i-code}}</td>
<td>Matches a string of digit characters</td>
<td>\d+</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">digit(s)</code></td>
<td>{{i-code}}digit(s){{end-i-code}}</td>
<td>Matches any digit character</td>
<td>\d</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">integer(s)</code></td>
<td>{{i-code}}integer(s){{end-i-code}}</td>
<td>Matches an integer</td>
<td>[+-]?\d+</td>
<td>&nbsp;</td>
<tr>
<td><code class="cm-s-idea">decimal(s)</code></td>
<td>{{i-code}}decimal(s){{end-i-code}}</td>
<td>Matches digits, an optional decimal point and more digits</td>
<td>[+-]?((\d+[,.]?\d*)|([,.]\d+))</td>
<td>Supports both "," and "." decimal points</td>
<tr>
<td><code class="cm-s-idea">character(s)</code></td>
<td>{{i-code}}character(s){{end-i-code}}</td>
<td>Matches a-z, A-Z, _, or digits</td>
<td>\w</td>
<td>For a-z only, use <code class="cm-s-idea">letter(s)</code></td>
<td>For a-z only, use {{i-code}}letter(s){{end-i-code}}</td>
</tr>
<tr>
<td><code class="cm-s-idea">whitespace(s)</code></td>
<td>{{i-code}}whitespace(s){{end-i-code}}</td>
<td>Matches any whitespace character</td>
<td>\s</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">(word )boundary</code></td>
<td>{{i-code}}(word )boundary{{end-i-code}}</td>
<td>Boundary between a word</td>
<td>\b</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">line feed</code>/<code class="cm-s-idea">newline</code></td>
<td>{{i-code}}line feed{{end-i-code}}/{{i-code}}newline{{end-i-code}}</td>
<td>Matches a newline</td>
<td>\n</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><code class="cm-s-idea">carriage return</code></td>
<td>{{i-code}}carriage return{{end-i-code}}</td>
<td>Matches a carriage return</td>
<td>\r</td>
<td>&nbsp;</td>
@ -225,111 +223,103 @@ match a word
</table>
<p>You can also create ranges of characters to match. Say for example, you wanted to match any characters between a and z, you could write any of the following:
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match from "a" to "z" // "from" is optional
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match between "a" and "z" // "between" is optional
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "a" ... "z" // can use "..." or ".."
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "a" - "z"
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match "a" through "z" // can also use thru
</code></span>
{{end-s-code}}
<br>
<p class="font-weight-bold" id="tut-repeition">7. Repetition</p>
<p>H2R supports 2 types of repetition: single match repetition, or grouped repetition. When using <code class="cm-s-idea">match</code> you can specify the number of captures you want just before the text to capture.
<span class="tutorial-code"><code class="cm-s-idea">
<p>H2R supports 2 types of repetition: single match repetition, or grouped repetition. When using {{i-code}}match{{end-i-code}} you can specify the number of captures you want just before the text to capture.
{{s-code}}
match 2 digits
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match exactly 2 digits
</code></span>
{{end-s-code}}
will match any 2 digits in a row. You can also specify a range you wish to capture
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match 2 ... 5 digits
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match 2 to 5 digits
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match between 2 to 5 digits
</code></span>
will match 2, 3, 4, or 5 digits. You can specify if the final number is exclusive with the <code class="cm-s-idea">exclusive</code> or <code class="cm-s-idea">inclusive</code> keywords.
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
will match 2, 3, 4, or 5 digits. You can specify if the final number is exclusive with the {{i-code}}exclusive{{end-i-code}} or {{i-code}}inclusive{{end-i-code}} keywords.
{{s-code}}
match 2 to 5 exclusive digits
</code></span>
{{end-s-code}}
will only match up to 4 digits. You can also choose to leave the end unspecified.
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match 2+ digits
</code></span>
{{end-s-code}}
or
<span class="tutorial-code"><code class="cm-s-idea">
{{s-code}}
match 2 or more digits
</code></span>
will match 2 or more digits. Repeition can be chained with the <code class="cm-s-idea">and then</code> keywords or the <code class="cm-s-idea">optional</code> keyword. For example:
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
will match 2 or more digits. Repeition can be chained with the {{i-code}}and then{{end-i-code}} keywords or the {{i-code}}optional{{end-i-code}} keyword. For example:
{{s-code}}
match 1+ digits then optionally "." then optionally 0...8 digits
</code></span>
{{end-s-code}}
Suppose you want to repeat a group of these match statements. You can group a repetition using the <code class="cm-s-idea">repeat</code> keyword. Everything underneath that is tabbed (scoped) will be repeated. By default, this will match 0 or more of the following statements.</p>
<pre class="tutorial-code">
<code class="cm-s-idea">repeat
Suppose you want to repeat a group of these match statements. You can group a repetition using the {{i-code}}repeat{{end-i-code}} keyword. Everything underneath that is tabbed (scoped) will be repeated. By default, this will match 0 or more of the following statements.</p>
{{p-code}}repeat
match "Hello "
match "World"
</code></pre>
<p>Will match 0 or more "Hello "s, but only 1 "World". The same qualifiers that exist for <code class="cm-s-idea">match</code> statements also exist for <code class="cm-s-idea">repeat</code> statements.</p>
<pre class="tutorial-code">
<code class="cm-s-idea">optionally repeat 3...7 times
{{end-p-code}}
<p>Will match 0 or more "Hello "s, but only 1 "World". The same qualifiers that exist for {{i-code}}match{{end-i-code}} statements also exist for {{i-code}}repeat{{end-i-code}} statements.</p>
{{p-code}}optionally repeat 3...7 times
match "Hello World"
</code></pre>
<p>Will potentially match "Hello World" between 3 and 7 times. H2R also supports the following for numbers: <code class="cm-s-idea">One, Two, Three, Four, Five, Six, Seven, Eight, Nine, and Ten</code></p>
{{end-p-code}}
<p>Will potentially match "Hello World" between 3 and 7 times. H2R also supports the following for numbers: {{i-code}}One, Two, Three, Four, Five, Six, Seven, Eight, Nine, and Ten{{end-i-code}}</p>
<br>
<p class="font-weight-bold" id="tut-grouping">8. Grouping</p>
<p>Just like regular expressions, capture groups are supported in H2R. Each group is defined using the <code class="cm-s-idea">create a group</code> keyphrase.</p>
<pre class="tutorial-code">
<code class="cm-s-idea">create a group
<p>Just like regular expressions, capture groups are supported in H2R. Each group is defined using the {{i-code}}create a group{{end-i-code}} keyphrase.</p>
{{p-code}}create a group
match "Hello World"
</code></pre>
{{end-p-code}}
<p>This will create a non-named captured group, equivalent to the regular expression "/(Hello World)/". A non-named captured group will show up in your chosen language's matches, however will not be given a name. To access this match, you will need to know the index of the group. Most regular expression engines support named capture groups, and H2R highly recommends using this feature. If you wish to do so, simply give it a name:<p>
<pre class="tutorial-code">
<code class="cm-s-idea">create a group called TestGroup
{{p-code}}create a group called TestGroup
match "Hello World"
</code></pre>
{{end-p-code}}
<p>In most languages, a named group can be accessed through the match result's group list. Take for example, in JavaScript,
<pre class="tutorial-code">
<code class="cm-s-idea">"hello".match(/(?&lt;TestGroup&gt;hello)/).groups</code>
</pre>
{{p-code}}"hello".match(/(?&lt;TestGroup&gt;hello)/).groups
{{end-p-code}}
<p>Will return an object with {TestGroup: "hello"}. For another example, check out <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#Using_named_capturing_groups">MDN web docs</a>. Groups can also be optional.</p>
<pre class="tutorial-code">
<code class="cm-s-idea">create an optional group
{{p-code}}create an optional group
match "Hello World"
</code></pre>
{{end-p-code}}
<p>And groups may be nested</p>
<pre class="tutorial-code">
<code class="cm-s-idea">create a group called TestGroup
{{p-code}}create a group called TestGroup
match "Hello"
create a group called InnerGroup
match "World"
</code></pre>
{{end-p-code}}
<p>The regular expression returned by this will be "/(?&lt;TestGroup&gt;Hello(?&lt;InnerGroup&gt;World))/". Again, in JavaScript, the following</p>
<pre class="tutorial-code">
<code class="cm-s-idea">"HelloWorld".match(/(?&lt;TestGroup&gt;Hello(?&lt;InnerGroup&gt;World))/).groups</code>
</pre>
{{p-code}}"HelloWorld".match(/(?&lt;TestGroup&gt;Hello(?&lt;InnerGroup&gt;World))/).groups
{{end-p-code}}
<p>Will return an object with {TestGroup: "HelloWorld", InnerGroup: "World"}.</p>
<br>
@ -345,18 +335,18 @@ match "World"
<p>TODO</p>
<p class="font-weight-bold" id="tut-unicode">Unicode character properties</p>
<p>You can match specific unicode sequences using <code class="cm-s-idea">"\uXXXX"
</code> or <code class="cm-s-idea">"\UXXXXXXXX"</code> where X is a hexadecimal character.
<span class="tutorial-code"><code class="cm-s-idea">
<p>You can match specific unicode sequences using {{i-code}}"\uXXXX"
{{end-i-code}} or {{i-code}}"\UXXXXXXXX"{{end-i-code}} where X is a hexadecimal character.
{{s-code}}
match "\u0669" // matches arabic digit 9 "&#x0669;"
</code></span>
Unicode character classes/scripts can be matched using the <code class="cm-s-idea">unicode</code> keyword.
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
Unicode character classes/scripts can be matched using the {{i-code}}unicode{{end-i-code}} keyword.
{{s-code}}
match unicode "Latin" // matches any latin character
</code></span>
<span class="tutorial-code"><code class="cm-s-idea">
{{end-s-code}}
{{s-code}}
match unicode "N" // matches any number character
</code></span>
{{end-s-code}}
The following Unicode class specifiers are available:</p>
<table class="table table-sm table-striped table-bordered">
<thead>

View File

@ -1,6 +0,0 @@
{
"page": {
"title": "Human2Regex Tutorial",
"description": "Create regular expressions with natural, human language"
}
}

View File

@ -4,10 +4,10 @@
/* eslint-disable no-undef */
const path = require("path");
const { glob } = require("glob");
const { render } = require("mustache");
const { readFileSync, writeFileSync, existsSync, mkdirSync } = require("fs");
const { minify } = require("html-minifier");
const CopyPlugin = require("copy-webpack-plugin");
const Handlebars = require("handlebars");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const WebpackBeforeBuildPlugin = require("before-build-webpack");
@ -32,32 +32,62 @@ const config = {
};
function build_mustache() {
function build_handlebars() {
if (!existsSync(config.dst)){
mkdirSync(config.dst);
}
const read_json_file = (filename) => JSON.parse(readFileSync(filename), "utf8");
const files = [
"404.hbs",
"index.hbs",
"tutorial.hbs"
];
const compress_html = (input) => config.prod ? minify(input, config.compression_config.html) : input;
// get views
const files = glob.sync(path.join(config.src, "docs", "*.json"));
// get partials
const partials = {
header: readFileSync(path.join(config.src, "docs", "header.mustache"), "utf8"),
footer: readFileSync(path.join(config.src, "docs", "footer.mustache"), "utf8")
const context = {
build: {
prod: config.prod+"",
year: new Date().getFullYear()+""
}
};
// build main mustache files
for (const item of files) {
const filename = path.basename(item, ".json");
const view = read_json_file(item);
const to = path.join(config.dst, filename + ".html");
const template = readFileSync(path.join(config.src, "docs", filename + ".mustache"), "utf8");
// helper functions
const compress_html = (input) => config.prod ? minify(input, config.compression_config.html) : input;
writeFileSync(to, compress_html(render(template, view, partials)));
Handlebars.registerHelper("i-code", function(options) {
return new Handlebars.SafeString(`<code class="cm-s-idea">`);
});
Handlebars.registerHelper("s-code", function(options) {
return new Handlebars.SafeString(`<span class="tutorial-code"><code class="cm-s-idea">`);
});
Handlebars.registerHelper("p-code", function(options) {
return new Handlebars.SafeString(`<pre class="tutorial-code"><code class="cm-s-idea">`);
});
Handlebars.registerHelper("end-i-code", function(options) {
return new Handlebars.SafeString('</code>');
});
Handlebars.registerHelper("end-s-code", function(options) {
return new Handlebars.SafeString('</code></span>');
});
Handlebars.registerHelper("end-p-code", function(options) {
return new Handlebars.SafeString('</code></pre>');
});
// get partials
Handlebars.registerPartial("header", readFileSync(path.join(config.src, "docs", "header.hbs"), "utf8"));
Handlebars.registerPartial("footer", readFileSync(path.join(config.src, "docs", "footer.hbs"), "utf8"));
Handlebars.registerPartial("example_code", readFileSync(path.join(config.src, "docs", "example_code.hbs"), "utf8"));
// build handlebar files
for (const filename of files) {
const to = path.join(config.dst, path.basename(filename, ".hbs") + ".html");
const template = readFileSync(path.join(config.src, "docs", filename), "utf8");
writeFileSync(to, compress_html(Handlebars.compile(template)(context)));
}
}
@ -84,12 +114,12 @@ module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{ from: config.src + "docs/" + "!(*.css|*.mustache|*.json)", to: "", flatten: true}
{ from: config.src + "docs/" + "!(*.css|*.hbs)", to: "", flatten: true}
]
}),
new MiniCssExtractPlugin({ filename: "bundle.min.css" }),
new WebpackBeforeBuildPlugin(function(_, callback) {
build_mustache();
build_handlebars();
callback();
}),
new RemovePlugin({