Regex search in gedit and GtkSourceView, finally

Regex search in gedit
Regex search in gedit

Although regular expression searches were possible with plugins, it is now available by default in gedit. The search and replace works too, and you can use backreferences (\0, \1, …) in the replacement text.

All this work has been merged upstream, just in time before the freeze.

Reworked search and replace API in GtkSourceView

Behind the scene, the regex search is implemented in GtkSourceView. For most cases, it scales well for big text buffers, since multi-segment matching is done: when a partial match is returned, we take a bigger segment. Read the lengthy implementation overview at the top of gtksourcesearchcontext.c for more details.

Besides the regex search, the API is now more flexible. Roughly speaking, it was initially a one-to-one relationship: only one search was possible at a time in a text buffer. It is now a many-to-many relationship: several searches can execute at the same time in the same text buffer (it can be useful for non-highlighted, background searches). And the search settings can be shared between several buffers.

Next step for my GSoC: rework the GtkSourceView style schemes to use CSS.

7 thoughts on “Regex search in gedit and GtkSourceView, finally”

    1. Of course, the regex search is disabled by default. In the search and replace dialog, the check button is visible, so no problem to find the option. In the simple search (Ctrl+F, what is shown in the screenshot above), the options are available on right click, or when clicking on the icon on the left of the search entry.

Leave a Reply

Your email address will not be published. Required fields are marked *