regex_automata missing replace? #1166
Replies: 1 comment 1 reply
-
Yes! It exists! The "lowest level" variant of it is in the It doesn't exist on
Have you looked at the implementation of The multi-pattern case could possibly complicate this somewhat, but it really depends on the semantics you want. You might not be able to use a multi-regex at all for example if the semantics are "do replacement for regex
I would perhaps caution you that if the primary purpose of your CLI tool is to do replacements, then it might actually be a good idea to provide your own syntax. Because the syntax supported by |
Beta Was this translation helpful? Give feedback.
-
What I'm trying to accomplish
I'm interested in implementing a user-configurable set of regex replacements on some input I will process. It would be quite similar to a multi-expression sed:
regex has replace (using
$1
etc for capture groups), but not in RegexSet (and RegexSet doesn't support captures like that). Instead the documentation directed me towards regex-automata, but that doesn't seem to have replacements either. I could implement something myself of course on top ofRegex::new_many
, but I had hoped there would at least be a parser in regex-automata for replacement strings, or some low level support for replacements at all.It also isn't clear to me how to implement something like sed's g-modifier (or rather lack of modifier), that is, how to make a pattern match at most once per line. While not essential, it would be nice to have for familiarity with users familiar with sed (which I expect my target audience to be, this is a tool for sysadmins / Unix greybeards, and yes I count myself to the latter group). It seems I would have to scan the ranges between matches for newlines and possibly discard matches if they are on the same line, keeping track of which pattern those matches originated from so that different patterns can still match on the same line.
Questions
So, what are my questions then?
Beta Was this translation helpful? Give feedback.
All reactions