Repetitive tasks are a prime example of problems AI can help you solve efficiently. We'll look at a file that has several function calls (measurePerformance
) that we could use a macro or regex to remove. Instead, we'll use Cursor composer to write the regex and make sure it handles all the cases we want.
[00:00] When you run into a scenario with a repetitive task such as removing this measure performance function throughout this entire file, you usually know it's something you could do with the regex or a macro or some other tool, but I often didn't take the time before and I did it manually. Now I'll just select all of it, hit command l, and say write the regex for removing the measure performance
[00:19] function, which is wrapping a bunch of functions in there. Make sure and cover every scenario. Then we'll let that work, paste that in, hit enter, then this writes it out and explains it. We just need this, so I'll hit copy here. Now if I hit command r for my find and replace, I'll paste in my regex, make sure regex is checked. Looks
[00:39] like it did give us an extra paren around here, and then the replace is the usual just dollar sign. So we'll copy that or write it out either way. Then I'll hit replace all. Oh, and it looks like it did need that extra paren, it just needed it escaped. So I'll undo, put the extra paren back in, but I'll escape it this time. Now we'll hit enter,
[01:00] and now that's taken care of for me. I also just noticed this didn't cover all of the scenarios, so I did have to ask a follow-up in chat saying analyze all of the scenarios in group test, then at sign, so that it could find the single line, the multiline, and nested function calls and everything. And then once I was done, it said use this as the
[01:20] find and then this as the replace. So after I did that, so these were before, then I ran it, and it got rid of all of those extra scenarios.