mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-12 14:54:42 -04:00
Use shared file to describe regex syntax
This commit is contained in:
parent
e75dee6b85
commit
d415bae24e
3
content/en/functions/common/index.md
Normal file
3
content/en/functions/common/index.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
+++
|
||||||
|
headless = true
|
||||||
|
+++
|
8
content/en/functions/common/regular-expressions.md
Normal file
8
content/en/functions/common/regular-expressions.md
Normal 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
|
@ -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`:
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
|
||||||
|
@ -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`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user