-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace
string literal cannot escape $
next to a capture group
#21462
Comments
@darinspivey it should be:
Had you already tried that? The |
This is mentioned here: https://vector.dev/docs/reference/configuration/#escaping. Admittedly it is one of the trickier foot guns to be aware of when using capture groups. |
Yes, I tried that, but it's not the desired outcome. The docs say to escape it with The intention is to grab the numeric price, and add a static |
Oh I see. You want a leading
The reason you need so many
The regex crate also uses Does that make sense? |
My goodness! I stopped trying after 4 dollars wouldn't work thinking that it would just rinse/repeat the behavior with 4. This indeed does work, although I would suggest adding some examples such as this to the docs. It's not quite enough to read that As an aside, do you have a similar fix for the single backslash problem mentioned above? Seems very similar, although it could be a separate string literal issue. Thanks, @jszwedko ! |
No worries! It is definitely confusing. I opened #21467 to try to better document it. For getting a single backslash character in string literals |
Absolutely. Thank you for the docs update on this issue--that's much clearer. |
A note for the community
Problem
There seems to be some issues with escaping certain things within string literals, as dollar sign
$
has multiple uses${VAR}
replace
command (which must be escaped with$$
in conf files)$
With the
replace
command, it is not possible to escape a$
immediately preceding a capture group, which is useful when dealing with price data. Consider the followingreplace_with
string literals, assuming the price has been placed in aprice
capture group:As an aside, a similar issue happens when trying to escape a single backslash within a string literal.
This condition may be a separate issue, but it also has a workaround. You can split the string literal into parts and use concatenation with the string type. but it's messy. For example,
s'endinbackslash' + "\\"
. However, this workaround does not work withreplace_with
because the concatenated string portion does not honor capture group names.Configuration
Version
vector 0.42.0 (aarch64-apple-darwin)
Debug Output
Example Data
The configuration provided will re-produce the problem with example data inline.
Additional Context
No response
References
There have been other issues regarding escaping
$
, but not this specifically. I did not look into the backslash condition since I found a workaround, although not ideal.${FOO}
but not$FOO
#8136The text was updated successfully, but these errors were encountered: