Skip to content

Commit

Permalink
Create main.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
crpietschmann committed May 8, 2024
1 parent e878d16 commit ef1e75f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions terraform-tips/string-replace/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
locals {
example_string = "The quick brown fox jumps over the lazy dog"
}

output "simple-replace" {
value = "${replace("hello world", "world", "terraform")}"
}

output "regex-replace-number" {
value = "${replace("hello world 123", "/[0-9]/", "X")}"
}

output "regex-replace-vowels" {
value = replace(local.example_string, "/[aeiou]/", "*")
}

output "regex-replace-non-alphanumeric" {
value = replace("Hello! This is a test string #123$%^", "/[^a-zA-Z0-9]/", "")
}

output "regex-replace-captured-strings" {
value = replace("John Doe (johndoe@example.com)", "/([a-zA-Z]+) ([a-zA-Z]+) \\(([^)]+)\\)/", "$2, $1 - Email: $3")
}

output "regex-replace-email-domain" {
value = replace("chris@build5nines.com", "/^[^@]+@([^@]+)$/", "$1")
}

output "regex-replace-remove-whitespace" {
value = replace("This is a test", "/[\\s]+/", "")
}

output "regex-replace-url-protocol" {
value = replace("https://build5nines.com", "/http[s|]?:\\/\\//", "")
}

output "regex-replace-remove-html-tags" {
value = replace("<p>Hello, <b>world</b>!</p>", "/<[^>]+>/", "")
}

output "regex-replace-normalize-phone-number" {
value = replace("+1 (555) 123-4567", "/[^\\d]/", "")
}

0 comments on commit ef1e75f

Please sign in to comment.