Is it possible to have nested regular-expression replace functions in Excel VBA and/or as a cell formula?
for example I have the following text: "Lorem [ipsum dolor sit] amet, [consetetur sadipscing] elitr." (note the square brackets)
is there any possibility to transform it to: "Lorem ipsum_dolor_sit amet, consetetur_sadipscing elitr."?
so i want to:
- find all the terms inside square brackets
- inside them: replace all blanks with an underscore
- remove the square brackets
and get returned the whole sentence with these replacements.
with my current attemp, I can only remove the brackets:
Function RegexReplace(...)
...
Set oRegex = CreateObject("VBScript.RegExp")
oRegex.Pattern = "\[([^\[\]]*)\]"
oRegex.Replace(strInput, "$1")
...
and nesting this function as formula in a Cell or inside the Code oRegex.Replace(strInput, Replace("$1", " ", "_")
seems not to be possible, because the nested replace-function Replace(..
is called before evaluating the replacement string $1
, so there is no blank to replace.
any proposals for solution? Thanks :-)