0

I'm using boost::regex_replace(replacement_text, regex, new_text) function to do this...

replacement_text = "{replace_me}"

regex = "(\{([^\}]*[^\s]*)\})"

new_text = "$$$"

For every new_text that doesn't contain "$", this works beautifully, new_text would completely replace the replacement_text. But when using the symbol "$$$", it truncates it to "$$", taking off 1 $.

I read that the dollar sign ($) in the specs are for special formatting:

$n

n-th backreference (i.e., a copy of the n-th matched group specified with parentheses in the regex pattern). n must be an integer value designating a valid backreference, greater than 1, and of two digits at most.

So how can I disable this so that it doesn't do special formatting? Thanks in advance!

unwise guy
  • 1,048
  • 8
  • 18
  • 27
  • 1
    I don't know much about boost, but typically, regex languages allow you to escape with a backslash - i.e. `new_text = "\$\$\$"` – happydave Oct 14 '12 at 23:37
  • Actually, since it's a C string, I guess the backslashes need to be escaped - so maybe `new_text = "\\$\\$\\$"` – happydave Oct 14 '12 at 23:39

1 Answers1

1

As you mentioned in your question, $ is an escape sequence in formatter parameter of regex_replace, so like any other special character in PCRE(Perl compatible regex) you can escape it using \! so use \$\$\$ and since you are using C++ you should use \\$\\$\\$(of course you know that already)

BigBoss
  • 6,904
  • 2
  • 23
  • 38