3

How to delete [ and ] characters in a string with Regex ?

I'm using the Puppet DSL function regsubst :

regsubst($::env, '\[\]', '', 'G')

thanks

4

1 に答える 1

7

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".

于 2012-10-19T09:28:16.040 に答える