Regex is using or statement wrongly
December 19, 2024 3:11 PM   Subscribe

I use a consecutive mixed character code to help me find plant names. Mainly I use Everything in non-Regex mode for searches, but I have started trying to use Regex (using Regex: on the search line, not via the menu workflow) as it offers dramatically better search quality. But I cannot Regex to work with or. A coded filename looks like:

Anigozanthos kangaroo paw e116_41r.jpg
Code explanation - e exotic, 1 dicot (broadleaf), 1 evergreen, 6 shrub form, underscore, 4 green, 1r red. The underscore enabless a connected readable string and reduces disambiguation.

so a search like: regex:e1[1-5][1-8]_[1-9]1r jpg
works and Anigozanthos is top of the list.

but e|n[1-4][1-5][1-8]_[1-9]1r jpg
Finds every jpg on my system with an e or an n anywhere and ignores the rest of the command.

What am I doing wrong? I have not found any Regex info on limiting a search to mixed consecutive alphanumeric characters in a string.
posted by unearthed to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
Looking at Everything's Regex documentation, it supports capture groups (using parenthesis). The issue is that your regex is "E, OR everything else in your regex", but you want "E OR N, AND everything else in your regex".

So (e|n)[1-4][1-5][1-8]_[1-9]1r\.jpg should work. I like Regex101 for testing regexes online.
posted by CrystalDave at 3:20 PM on December 19 [5 favorites]


alternatively
[en] will match e or n followed by the numbers you're interested in
posted by kokaku at 4:32 PM on December 19 [4 favorites]


Response by poster: Thanks CrystalDave

I found that Everything's Regex needs "|" around pipe characters [Everything forum]:

regex:(n"|"e)

Thanks kokaku.
posted by unearthed at 4:51 PM on December 19 [1 favorite]


« Older Shows (magic or otherwise) with implications that...   |   (UK Lake District) Things to do in Keswick this... Newer »

You are not logged in, either login or create an account to post comments