Search code examples
regexgreppcretextwrangler

How to match and replace n number of times with RegEx


I'm using TextWrangler, the free version of BBEdit on the Mac, which I understand uses the PCRE engine.

What I want to do is match a specific number of lines and replace as well.

After a lot of searching I came up with this:

(^(.*\r)){25}

This lets me match up to 25 lines. It works great, but the problem comes when I want to actually replace something. I can't figure out how to do it.

For example, I would like to replace all of the returns "\r" with tabs "\t".

Hopefully this is actually possible. I'd appreciate any help. Thanks!


Solution

  • Regexp domain is searching. You cannot replace using regexp; a programming language or editor can use regexp as the search part of its search-and-replace function. Thus, the way to do 25 replacements is purely in the domain of said programming language or editor. If it does not provide such capability, either directly in search-and-replace or as a macro/loop/other, then you cannot do it automatically.