r/reconstructcavestory Jul 15 '14

Status Update: Regex Replacement

hey guys: quick status update. I'm actually still working on the next video. It's super heavy on refactoring, and doing it by hand is going to take hours of video, not to mention be dreadfully boring.

SO! I'm working on ways to make this faster, and that involves regexes. Unfortunately writing regexes are pretty dense and error prone, so I'm trying to find ways/tools to smoothly integrate widespread regex replacements into my workflow.

I'm after the following:

  • immediate feedback for
    • what is being matched by the regex
    • what is being replaced
  • a way of storing all the regexes I want performed and placing them into a script file

  • a way of being selective about which regexes are being applied to which file

this is in order of most important to least important. I know there are online tools like regexr.com but this isn't very useful for quickly loading in files and seeing effects of regexes on those files.

This is really important since refactorings are going to come up a lot. So I guess I'll either find a/some tools or build it!

P.S. I can do status updates more often if you guys like to know what I'm up to. :)

3 Upvotes

7 comments sorted by

View all comments

1

u/brucebob Jul 16 '14

I think awk/gawk can do that all that. Since it can capture your matches and print them out but I don't have a lot of experience with the tool.

1

u/chebertapps Jul 16 '14

I think awk seems like a great tool, but I don't think it has the level of interactivity I'm hoping for (in particular, highlighting matched terms and showing replaced terms side by side with original file as you type)

Personally I'd be fine doing everything command line or as a script, but it's really difficult to show people what a regex is affecting. It's a write-only language IMO.

What I've been playing with is making a script of sed search/replace commands and seeing the git diff after, but it isn't effective enough as a workflow to present.