Select Next regex match?


I’m trying to select multiple strings that match a regex, but when I use the Select Next command, it selects the next instance of the currently highlighted matching result, not the next instance that matches the regex.

I am trying to match hashtags. I am using the regex #[a-z]+\b\s

If I have tags such as #tag1 and #tag2, when I invoke the regex search and it matches #tag1, invoking Select Next will only select the next instance of #tag1.

I want to select the next instance(s) of all tags that match the regex, not instances that match the currently highlighted string.

Is this possible?


There are some issues with find and replace live preview currently, but I don’t know what’s causing yours. A full example, including text that can be copied and pasted, would help us see what’s wrong.

Also, that word break looks redundant. (Edit: I think it’s supposed to be a digit)


As far as real copy/paste examples, I was using that regex on personal journal entries with various hashtags ending each entry. For some entries, I just wanted to delete all the hashtags (they were social media hashtags, and not my file sorting hashtags). I wanted to use the regex to hop to each hashtag, and then be able to Select Next to be able to select all the successive hashtags appended to an entry, so I could delete them.

See were woven into the text, so not collated at the end of the entry.

For example:

Bike ride to grocery store. #bicycle #shopping #groceries
#photoshop #tutorial on key object selection alignment. #software

I was using the regex to jump to instances of hashtags, so I could evaluate them. I wanted to then use the Select Next to highlight the tags I wanted to delete.

In the above example, I would want to use the regex/“Select Next” combo to highlight then delete the three hashtags #photoshop #software #tutorial

Regarding the regex pattern, the word break indeed seemed redundant, but if I recall correctly I was unable to get my regex to match hashtags properly without it; I use underscores in many hashtags, which at least on macOS and iOS are seen as part of the word string. But Atom’s regex wasn’t doing something I needed without inclusion of that ending word break meta character.

I’m new to regex so I may be doing something inelegant.


Oh, I think there’s a misunderstanding. select next is unrelated to the expression in the search box; it takes the word the cursor is on, and finds the next match for that (hence why it only found tag1 after the first one). The find next command might be what you want (it will select the word too).

As for the regex itself, I don’t know much about macOS regular expressions. In JS though (the engine Atom uses in find and replace), a word character is equivalent to [a-zA-Z0-9_]. The following expression found all the tags in your example


As I said above, there are issues with the live preview, but they (seem to) only apply to expressions with lookahead. Feel free to post with an example if it’s not working for you, and I’ll try to take a look.


Aha, I was hoping there was a way to quickly find/select each successive regex match on an individual basis, but looks like I’ll have to find next & delete. Was hoping to eliminate the need to delete after each find. Thanks for clarifying that this is not possible in Atom.

And your regex worked fine in my end. Mine was unnecessarily verbose :slight_smile: