検索

Solved a *problem with #regex with more regex today.

*Not actually a problem with the regex itself, but one of unclear business requirements, but for anyone that said I'd regret the DNS regex I wrote a month later, I ate that soup today and it honestly wasn't bad.
返信 1 · Renote 0

返信元:

If the regex is more elaborate than a simple string matcher, suggest they use named groups, if they are not already. This will make debugging it way easier in the future if there are changes in the input structure, since isolating the problem area gets much easier when you can cherry pick sections of the regex and test match.

If the regex is being introduced, it's reasonable to ask the submitter to break down what it does and give insight into how to test/debug it.
返信 2 · Renote 0
Like any tech, #regex feels like black magic until you understand it.
返信 1 · Renote 0
The thing about coding with #regex is that it feels like I'm getting paid to do Sudoku puzzles for a living.

Tip for those who are asked to review code with regex: Rather than focusing on the regex itself, ask to see the automated tests that it is ran against and look for gaps in the tests rather than getting lost in the weeds with scrutinizing the regex itself unless there's an obvious *significant* performance problem.
返信 3 · Renote 0
These are the two lines of code (minus some constants and file operations) that saved me a while lot of tediousness, today... #ruby #regex #programming #Jenkins

It ended up being a bit more involved than my post earlier, but was able to script it to automate the patching and PRs. It looks terrible, but I'm pretty happy with the end result.
  • e380f66047b588be.jpg
返信 2 · Renote 0

返信元:

Very understandably, not one coworker has volunteered to review my PR so far. One of them glanced at it. I know this because I heard them say from their office down the hall "Uh oh! regex with backrefs in Ansible? This can't be good..." and then left no comment on the PR. And you know what - I can't blame them.
返信 2 · Renote 0
Just in case this doesn't make sense to anyone, #Ansible has a commonly used tool called lineinfile that let's you do things like update server config files. You can use regex to identify which line up update. With backrefs, you can do some particularly intricate/powerful things so that the line that is written can be a combination of #regex matches and ansible variables. https://dev.to/ferricoxide/code-explainer-regex-and-backrefs-in-ansible-code-gn7
返信 1 · Renote 0