Use shared file to describe regex syntax

This commit is contained in:
Joe Mooring 2023-08-03 11:45:59 -07:00 committed by GitHub
parent e75dee6b85
commit d415bae24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 60 deletions

View File

@ -0,0 +1,3 @@
+++
headless = true
+++

View File

@ -0,0 +1,8 @@
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
Go's regular expression package implements the [RE2 syntax]. The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats]. Note that the RE2 `\C` escape sequence is not supported.
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
[RE2 syntax]: https://github.com/google/re2/wiki/Syntax/
[string literal]: https://go.dev/ref/spec#String_literals

View File

@ -13,21 +13,7 @@ relatedfuncs: [findRESubmatch, replaceRE]
--- ---
By default, `findRE` finds all matches. You can limit the number of matches with an optional LIMIT parameter. By default, `findRE` finds all matches. You can limit the number of matches with an optional LIMIT parameter.
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. {{% readfile file="/functions/common/regular-expressions.md" %}}
[string literal]: https://go.dev/ref/spec#String_literals
This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.
[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/
{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
This example returns a slice of all second level headings (`h2` elements) within the rendered `.Content`: This example returns a slice of all second level headings (`h2` elements) within the rendered `.Content`:

View File

@ -14,21 +14,7 @@ relatedfuncs: [findRE, replaceRE]
By default, `findRESubmatch` finds all matches. You can limit the number of matches with an optional LIMIT parameter. A return value of nil indicates no match. By default, `findRESubmatch` finds all matches. You can limit the number of matches with an optional LIMIT parameter. A return value of nil indicates no match.
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. {{% readfile file="/functions/common/regular-expressions.md" %}}
[string literal]: https://go.dev/ref/spec#String_literals
This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.
[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/
{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
## Demonstrative examples ## Demonstrative examples

View File

@ -13,21 +13,7 @@ relatedfuncs: [findRE, FindRESubmatch, replace]
--- ---
By default, `replaceRE` replaces all matches. You can limit the number of matches with an optional LIMIT parameter. By default, `replaceRE` replaces all matches. You can limit the number of matches with an optional LIMIT parameter.
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. {{% readfile file="/functions/common/regular-expressions.md" %}}
[string literal]: https://go.dev/ref/spec#String_literals
This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.
[RE2]: https://github.com/google/re2/
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/
{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
This example replaces two or more consecutive hyphens with a single hyphen: This example replaces two or more consecutive hyphens with a single hyphen:

View File

@ -109,25 +109,12 @@ You can also put the returned value of the `where` clauses into a variable:
This example matches pages where the "foo" parameter begins with "ab": This example matches pages where the "foo" parameter begins with "ab":
```go-html-template ```go-html-template
{{ range where site.RegularPages "Params.foo" "like" "^ab" }} {{ range where site.RegularPages "Params.foo" "like" `^ab` }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }} {{ end }}
``` ```
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes. {{% readfile file="/functions/common/regular-expressions.md" %}}
[string literal]: https://go.dev/ref/spec#String_literals
Go's regular expression package implements the [RE2 syntax]. Note that the RE2 `\C` escape sequence is not supported.
[RE2 syntax]: https://github.com/google/re2/wiki/Syntax/
{{% note %}}
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
[PCRE]: https://www.pcre.org/
{{% /note %}}
## Use `where` with `first` ## Use `where` with `first`