Regex: How to reference capture group from variable? #1224
Unanswered
archetyped
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do you reference a regex capture group when using a replacement string stored in a variable when using
=~
to evaluate a string against a regex? All capture group references are simply returning\1
,\2
, etc., not the capture group's value.Simple example:
Output:
The expected output is that both variable-based and inline should be the same. However, the replacement using a variable's value just returns
\1
, not the actual value from the captured group (i.e.something
).This is a simple example, but in actual practice, I have multiple regex patterns, each with a replacement string that references capture groups in different ways, so a way to turn those capture group references into the captured value would be greatly appreciated.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions