Myeongjang JO
Myeongjang JO

Reputation: 91

How can i use regular expression to extract specific word without lookahead on Terraform

I need help using regular Expression on Terraform

I usually use lookahead when I want to extract word that is between word to word.

For example. If want to get "DB" from "JMJ-TEMP-DB-SUB-C" or "JMJ-TEMP-DB-SUB-A", I use the regular expression as "[A-Z]+(?=-SUB)"

However, Terraform doesn't support lookahead..

I got an error Invalid function argument as "invalid regexp pattern: invalid or unsupported Perl syntax in (?=."

Please help me with how I can get a word between TEMP and SUB in "JMJ-TEMP-{word}-SUB-C"

If you don't understand my question, aks more please. I will explain in more detail.

Upvotes: 0

Views: 1053

Answers (1)

Alon Adler
Alon Adler

Reputation: 4024

Use the following regex:

TEMP-([A-Z]+)-SUB

And extract the capture group.

Here is a working example of the regex.

Upvotes: 1

Related Questions