mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
1.0 KiB
1.0 KiB
title, description, categories, menu, keywords, signature, relatedfuncs
| title | description | categories | menu | keywords | signature | relatedfuncs | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| findRE | Returns a slice of strings that match the regular expression. |
|
|
|
|
|
By default, findRE finds all matches. You can limit the number of matches with an optional LIMIT argument.
{{% readfile file="/functions/common/regular-expressions.md" %}}
This example returns a slice of all second level headings (h2 elements) within the rendered .Content:
{{ findRE `(?s)<h2.*?>.*?</h2>` .Content }}
The s flag causes . to match \n as well, allowing us to find an h2 element that contains newlines.
To limit the number of matches to one:
{{ findRE `(?s)<h2.*?>.*?</h2>` .Content 1 }}
{{% note %}} You can write and test your regular expression using regex101.com. Be sure to select the Go flavor before you begin. {{% /note %}}