# Version 0.5- Make replace an optional parameter defaulted to "" (empty string)- Allow override actions to use instead of replace: fold and unfold

Currently all finds are regex with option scope qualifiers. I plan on implementing the opposite as well: scope searches with regex qualifiers. That way you can find all regions of any scope and apply an optional regex on the region and determine if you want to do something to it.

If I have enough time today, I plan on pushing out the option to do multi-passes using a regex sequence.

There are times when you have a regex that can be fairly complicated and can only find one instance of a particular target on a line. The nature of regex is that it can only find a finite number of matches. So if the complexity is so great that it is not feasible to target all in a single pass, multi-pass can help.

For example (I got this from another post today):Somebody wanted to find instances of un-escaped dollar symbols between a certain tag. It is easy enough to target one, but to target an unknown number is quite a bit more difficult without perform regex on the regex result returned.So this example will find one instance for every content tag.

But I plan on adding a feature that will keep sweeping the file until no instances are found (or if you hit some threshold; I want to protect against infinite loops due to bad regex defines).

I think this will be a pretty good feature, and it shouldn't be to difficult to implement; I have most of it done already; I just need to restrict it to replace actions only and maybe update how I do feedback results to work with multi-pass.

Just a heads up; I will be commenting out all of the default commands except the "Reg Replace: Regex Input Sequencer" and "Reg Replace: Clear Highlights". I originally added the others as examples, so that is why I am going to have them commented out and remain, but I realized, I didn't want all of them, and they would have to be removed after every update.

So, moving forward, I will leave the default replace definitions in place because they hurt nothing and you can override them in your User folder if you don't want them. And I will leave the two commands mentioned above in place and comment out the rest so they can still be used as examples. I you like any of them, you can simply copy them to your Packages/User/Default.sublime-commands file, and those will persist with updates.

Figured I needed to mention it though in case some people used any of them and they disappeared on them.

# Version 0.7- Replace command examples now commented out by default- RegReplace Commands and Settings now available via preference menu and command palette

Very small update. So default replace commands are commented out, you can define your own in Default.sublime-commands in your User directory. Now you don't have to delete the default ones every time if you didn't want them.

These are definitions and commands for comments. Some C/C++ style, CSS (c multi-line), python style, and batch. They also come in multi line (where applicable), single line, and consecutive single line (good for code folding).

What is nice about these, is that they seem to work pretty good with folding without collapsing the next line into the first line. They seem to be working pretty good for me.

They can get a little tripped up with some symbols in strings. Like if you have a comment symbol in a string and comment at the end of a line, but it isn't too bad.

This is quite common for regex though. You pretty much have to parse the entire line to determine where comments really start and stop. And in some languages it is easier than others. Currently if you parse the entire line, you may be able to target comment exactly, but currently "fold" actions etc, are performed on the entire regex selection. I do not allow fine targeting of regions within a regex at this time, maybe in the future.

Eventually, I will get the scope searching done, with regex qualifiers, and then comments can be targeted very accurately.

Okay, so I now have scope searching working, but I am not committing it yet; I only have parts of it working.

I have it now where you can greedily find scopes and apply an optional find and replace with regex on those scopes (greedy or non-greedy).

I do not have non-greedy scope search done yet. I do not have literal search and replace on a scope done yet either. But it does work great on greedy scope searches with regex. I have been playing around with, and it just made all of my regex for comments obsolete. .

Should have a new release out tonight hopefully; if not, tomorrow for sure.

I have the "searching by scope and then applying regex to the scope region" feature pretty much done (I am skipping literal find and replace for now). Something to note though, due to the nature of Python's subn function, you need to be careful with optional captured groups. Normally you will expect something like this to return an empty string for group 1 if this or that is not found.

This only applies to regex applied to scope regions. Regex with scope qualifiers goes through ST2's api which does not suffer from this.I could use Python's findall function, but then I have to perform some coding gymnastics which I am not anxious to do right now, maybe down the road; we will see.

I also modified the folding command to not fold the trailing newline at the end of a selection. This makes folding regex much better, especially when targeting scopes like comments.

I also added a "mark" and "unmark" command where you can permanently highlight regions based on regex and also clear them; not sure how much use one might get out of this one, but it was easy to add, so I went ahead. It might come in handy.

# Version 0.8- New "mark" and "unmark" actions- Return error dialog showing regex issue- Add support for scope search with regex find and replace in scope region- Smarter folding of regex regions for "fold" action- Small tweak to non-greedy algorithm- Change default of optional replace parameter to "\\0"; do not delete by default, leave unchanged by default.- Allow spaces in the "Regex Input Sequencer"

One big thing to stress is the change of the default value of replace. If you have definitions that relied on the old default of "", the new default is "\\0". I decided it was better to not replace anything by default instead of deleting everything by default.

The other thing to note, is now when you create a malformed regex expression, you should get an error dialog giving you the internal error: things like unmatched brackets etc.

So now that scope selection is in, it is super easy to target difficult things like comments in every language. Here is a simple definition to delete all comments.

This is included in the default settings. It simply removes the comments leaving the line in tact

The mark and unmark actions are pretty self explanatory. It simply allows you to highlight specific searches by whatever scope you choose. You can have multiple different regex highlights on the screen at the same time as long as you give them unique keys. How to use them is documented in the readme. The highlights will persist until you delete the region, or clear them with the unmark command, etc. I guess it might be good if you have things you are always looking for in certain files. You can make them stand out a lot. It might not be that useful, it is kind of similar to the "find_only" option; the only difference is it doesn't disappear until you clear it. But it was easy to to add...so there it is.