How to delete [
and ]
characters in a string with Regex ?
I'm using the Puppet DSL function regsubst :
regsubst($::env, '\[\]', '', 'G')
thanks
Brackets are metacharacters in a regex and need to be escaped (and put in a character class if you want to match either one):
regsubst($::env, '[\[\]]', '', 'G')
Your version was only matching the exact string []
.
In a regex, [abc]
means "Match one of the following: a
, b
or c
".