findRe.md (1533B)
1 ---
2 title: findRE
3 description: Returns a list of strings that match the regular expression.
4 date: 2017-02-01
5 publishdate: 2017-02-01
6 lastmod: 2017-02-01
7 categories: [functions]
8 menu:
9 docs:
10 parent: "functions"
11 keywords: [regex]
12 signature: ["findRE PATTERN INPUT [LIMIT]"]
13 workson: []
14 hugoversion:
15 relatedfuncs: []
16 deprecated: false
17 aliases: []
18 ---
19
20 By default all matches will be included. The number of matches can be limited with an optional third parameter.
21
22 The example below returns a list of all second level headers (`<h2>`) in the content:
23
24 ```
25 {{ findRE "<h2.*?>(.|\n)*?</h2>" .Content }}
26 ```
27
28 You can limit the number of matches in the list with a third parameter. The following example shows how to limit the returned value to just one match (or none, if there are no matched substrings):
29
30 ```
31 {{ findRE "<h2.*?>(.|\n)*?</h2>" .Content 1 }}
32 <!-- returns ["<h2 id="#foo">Foo</h2>"] -->
33 ```
34
35 {{% note %}}
36 Hugo uses Go's [Regular Expression package](https://golang.org/pkg/regexp/), which is the same general syntax used by Perl, Python, and other languages but with a few minor differences for those coming from a background in PCRE. For a full syntax listing, see the [GitHub wiki for re2](https://github.com/google/re2/wiki/Syntax).
37
38 If you are just learning RegEx, or at least Go's flavor, you can practice pattern matching in the browser at <https://regex101.com/>.
39 {{% /note %}}
40
41 [partials]: /templates/partials/
42 [`plainify`]: /functions/plainify/
43 [toc]: /content-management/toc/
44 [`urlize`]: /functions/urlize