• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Nomad
  • Install
  • Intro
  • Tutorials
  • Documentation
  • API
  • Tools
  • Plugins
  • Sign up
Nomad Home

Documentation

Skip to main content
  • Documentation


    • Overview
      • Overview
      • Expressions
        • Overview
          • chomp
          • format
          • formatlist
          • indent
          • join
          • lower
          • regex_replace
          • replace
          • split
          • strlen
          • strrev
          • substr
          • title
          • trim
          • trimprefix
          • trimspace
          • trimsuffix
          • upper
      • Locals
      • Syntax
      • Variables
    • artifact
    • affinity
    • change_script
    • check
    • check_restart
    • connect
    • constraint
    • csi_plugin
    • device
    • dispatch_payload
    • env
    • ephemeral_disk
    • expose
    • gateway
    • group
    • job
    • lifecycle
    • logs
    • meta
    • migrate
    • multiregion
    • network
    • parameterized
    • periodic
    • proxy
    • reschedule
    • resources
    • restart
    • scaling
    • service
    • sidecar_service
    • sidecar_task
    • spread
    • task
    • template
    • update
    • upstreams
    • vault
    • volume
    • volume_mount
  • Schedulers

  • Nomad Ecosystem
  • Nomad Partnerships
  • Who Uses Nomad
  • FAQ

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Nomad
  3. Documentation
  4. Job Specification
  5. HCL2
  6. Functions
  7. String Functions
  8. regex_replace
  • Nomad
  • v1.3.x
  • v1.2.x
  • v1.1.x
  • v1.0.x
  • v0.12.x
  • v0.11.x

»regex_replace Function

regex_replace searches a given string for another given substring, and replaces each occurrence with a given replacement string. The substring argument can be a valid regular expression or a string.

regex_replace(string, substring, replacement)

substring should not be wrapped in forward slashes, it is always treated as a regular expression. The replacement string can incorporate captured strings from the input by using an $n or ${n} sequence, where n is the index or name of a capture group.

Examples

> regex_replace("hello world", "world", "everybody")
hello everybody


> regex_replace("hello world", "w.*d", "everybody")
hello everybody

> regex_replace("-ab-axxb-", "a(x*)b", "$1W)
---

> regex_replace("-ab-axxb-", "a(x*)b", "${1}W")
-W-xxW-

Related Functions

  • replace searches a given string for another given substring, and replaces all occurrences with a given replacement string.
Edit this page on GitHub

On this page

  1. regex_replace Function
  2. Examples
  3. Related Functions
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)