Sublime Forum

Snippet to select with regex?

#1

Hello. Is it possible to make a snippet that’d select several elements that match with specified regex?
I have a text file like this:

80101_1: blabla
80101_2: blabla
80101_72: blabla
80101_73: blabla
80101_5: blabla
80101_91: blabla
80101_112: blabla
80101_1252: blabla
80101_132: blabla

and I want to select all the numbers that go after 80101_ with one hotkey press. I’ve seen a package that allows to select with regex but it requires to type the regex every time.
Thanks!

0 Likes

#2

I would see if the RegReplace package has an action to select text instead of replacing it. You can bind that to hotkeys easily.

1 Like

#3

Thanks for answer. Yes, that could work!
However I just realised that forgot to mention that I want it to work with selection (first number, 80101 in my example, may be any number) but I can’t seem to find a way to use current selection in the find pattern

0 Likes

#4

In this instance, you may have to venture into writing your own routine for this. I think it would be generally pretty easy though because the command could extract the current selection and then remove that region, and then find all lines with the number and suffix and create a multiple region selection.

2 Likes

#5

RegReplace does have an option for selecting found regions, but it doesn’t currently take an input from selection. I have thought about allowing RegReplace to receive inputs via selections before though, but my development is mainly driven by needs, and while I’ve thought about it, I’ve never had the need.

If this is something you have a desire for, I’d create an issue over at RegReplace. I can’t promise when I’d have a solution, but I would consider this request.

2 Likes

#6

Thanks guys! As this is something very specific and I don’t really need anything too complex I’d probably try to make my own plugin as Remi suggested.
However for more flexibility I’d prefer to have this as an option in RegReplace, so I’ll create an issue (and also I’m quite sure that I won’t be able to write my own plugin haha, in this case I’ll wait for RegReplace to update and by now switch to more manual method I used before)
Cheers!

2 Likes

#7

RegReplace now supports selection inputs. This feature is experimental and may change as feedback comes in. Here’s documentation: http://facelessuser.github.io/RegReplace/usage/#selection-inputs.

2 Likes