Full RE2 syntax reference at > https://github.com/google/re2/wiki/Syntax Go RegExp doc at > https://golang.org/pkg/regexp/ More about general concepts > http://www.regular-expressions.info​
Basics of Regular Expressions
You can match a word by putting it between two brackets.
As example, this will only match the word "Dinosaur": (Dinosaur)
Using ?:
after opening parenthesis of a capturing group creates a non-capturing group. Useful for example with template function reFindAllSubmatches
.
This will not sub-match the words "red, blue, green":
{{ reFindAllSubmatches `(?:color=)(red|blue|green)` "color=red beautiful" }}
To clarify more - it will not show dateid,
because it's a whole match:
{{ slice (index (reFindAllSubmatches `(?:dateid=)([0-9]{5})` "dateid=12345") 0) 1 }}
You may also want to catch multiple options, for that we use a "Vertical bar" or also known as a "Pipe" between linux users.
As example, this will match if either "Cat" or "Dog" is present: (Cat|Dog)
To match anything of any length, use .*
.
Character classes
To match a word, you put it between two brackets.
Example: (Banana)
Sometimes you have to use special characters but it may cause conflicts. In this case, you will have to use an escape character.
For example, this is a star that doesn't interfere with other matches \*
.
If you still do not know what Regex are or want to know more. Check out the cheat sheet on the site below.
​