2

I have a yaml template with content like that:

Example 1:

- key: MY_KEY 
  value: "{{ $MY_VAL }}"

Example 2:

- key: MY_KEY 
  value: "$MY_VAL"

Example 3:

- key: MY_KEY 
  value: '$MY_VAL'

Example 4:

- key: MY_KEY 
  value: 'MY_VAL'

I want to match with regex MY_VAL incase of MY_KEY with new line (\r\n) then MY_VAL, but just incase it's not any kind of variable and it's a real value (e.g alphanumeric).

In the above Example 1 & Example 2 & Example 3 => I want it will return no match.

In Example 4 I want it will return there is a match.

I tried this regex with no success (IMHO I thought it will work, but it's not):

MY_KEY[\r\n]+[^${}].[\w].([^\r\n]+)

I follow that question of multiline regex, but it's not help in this case:

https://stackoverflow.com/a/37526464

Please help :D

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

You may use

MY_KEY[^\S\r\n]*[\r\n]+[^\S\r\n]*\w+:[^\S\r\n]*'(\w+)'

See the regex demo

Details

  • MY_KEY - a literal string
  • [^\S\r\n]* - 0 or more whitespace chars other than CR and LF
  • [\r\n]+ - one or more CR or LF chars
  • [^\S\r\n]* - 0 or more whitespace chars other than CR and LF
  • \w+ - one or word chars
  • : - a colon
  • [^\S\r\n]* - 0 or more whitespace chars other than CR and LF
  • '(\w+)' - ', 1+ word chars, '.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563