Hugo 0.16 - Regular Expressions!

Will the great creators from above bestow upon us lesser nobles the powers of regular expressions in the upcoming release of hugo 0.16? As a lowly user who has taken great pleasure in designing elaborate work arounds for routines that might be construed as “trivial” for regular expressions… I’m willing to sacrifice my pride, a slower hugo build time, and even bep’s blessings in return for the holy grail of pattern matching functionality.

Love, Professor Nunamaker XOXO

1 Like

I got lost in your interpretive dance routine. What do you want? Hugo vNext will have findRE and replaceRE.

1 Like

Good news Cameron, thanks for sharing.

Suggested Naming: replacere or rereplace

Current Syntax (Example):
{{ replaceRE "^https?://([^/]+).*" "$1" "http://gohugo.io/docs" }} → "gohugo.io" e.g. {{ "http://gohugo.io/docs" | replaceRE "^https?://([^/]+).*" "$1" }} → "gohugo.io"

Suggested Syntax:
{{rereplace "string text" "pattern text" "replacement text" "optional flags"}} {{rereplace "<h2 class="beps">wife's son</h2>" "<h2 [^>]+>([^<]+)<\/h2>" "minivan" "$1" }} → "<h2 class="beps">minivan</h2>"

@moorereason Maybe this is a dumb question, but could replaceRE and findRE have implications for the TOC shortcode? That is, creating a top-level ul > li based on the highest level heading within body copy rather than being based on h1/h2/h3 as it is now? I ask because I see this as the biggest shortcoming of the TOC shortcode right now.

OR a more powerful feature would be able to pass an argument(s) showing the starting/ending heading level for the TOC (eg, creating the div/nav starting at h3 and h4 rather than h1/h2).

current
{{.TableOfContents}}
better
{{.TableOfContents "h3" "h5" }}

Nevertheless, I dig the CSS hack mentioned in other feeds, but ultimately the markup should stay true to the content…

Please don’t fill this forum with regexp hacks.

1 Like

@bep the keyboard warrior has :heart: Bep Blessed :heart: us with his presence :slight_smile:
Would you like me to hold your hand and help you tip toe through these little pattern matching games? Man up, be a leader…not a dictator.

1 Like