std::regex to find word within brackets inside a string, then replace it
(and the brackets)
Having some trouble with this one. I'm using std::regex for the first time
and the syntax is a little unintuitive to me.
I've got strings with stuff like [VARIABLE] and sometimes [VARIABLEA] \
[VARIABLEB].
Let's say for example I want to replace [VARIABLEA] with Windows and
[VARIABLEB] with System32, so the result would be Windows\System32.
What do you think the best regex would be for finding these matches? What
do you think the best method for replacing them is?
I basically have been streaming into a Stringstream for my replacements
(When I find a match i put in the the new value, when I don't i put in the
original key, for all else I just stream in). But I wasn't sure if
std::regex maybe provided some better option for this.
Here's the regex I've been trying: std::regex("\\\\*\\[[^\\]]*\\]\\\\*");
I'm on a fairly tight schedule and just been banging my head on the desk
for too long with this one. I know it's probably very simple, but I am a
slow learned. Thanks in advance for any help you can provide.
No comments:
Post a Comment