Regex ignores caret?

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
ksad
Posts: 4
Joined: Wed Feb 02, 2022 4:40 pm

Regex ignores caret?

Post by ksad »

I'm learning regex and have decided to try it out inside Everything. I started with a simple regex:^[a-g] and got only results with said letters, despite the caret being a "not" operator in regex. I wondered if this might be an issue with my keyboard's caret being weird (I use a standard Croatian QWERTZ keyboard, the caret is supposedly achieved by holding altgr+3+space), but it also doesn't work even when I paste the caret in, or if I change to English keyboard and use shift+6.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Regex ignores caret?

Post by NotNull »

Your keyboard is probably OK. The caret can be used in multiple ways in regex:

^a = Marks the start of the filename (^), followed by an "a"
[^a] = any character that isn't an "a"

Those combined:
^[^a] = the filename does *not* start with an "a"


So your regex:^[a-g] will show all fileanmes that start with an a, b,c ... or g



ksad wrote: Fri Mar 04, 2022 2:09 pm I'm learning regex and have decided to try it out inside Everything.
Good choice! :D
90% of what I know about regex, I learned through Everything.
On the one hand because you got a lot of different filenames to test against.
On the other hand, because Everything documented a clever subset of all regex features. With those 20% you can do 80+ percent of all regex tasks. It's less overwhelming when you start out.
On the other-other hand (I know .. Everything is quite 'handy' :lol: ) there is always the Everything forum to help you on your way. It certainly did for me.


This helped me a lot:
https://www.voidtools.com/support/every ... ing/#regex
ksad
Posts: 4
Joined: Wed Feb 02, 2022 4:40 pm

Re: Regex ignores caret?

Post by ksad »

Oh...You're right! I even had it in my notes, but I was so focused on the "NOT" meaning (which I kept associating with Everything's "!") that I completely missed the other use that was mentioned right under it. I was so frustrated that even the simplest regex search was failing me, but it's finally working!

Everything actually opened my eyes in regards to more advanced search, and I decided to take it a step further with regex. The first time I tried learning regex a year or so ago it seemed like such a confusing mess, but after I slowly eased into Everything's syntax, everything it's all so much easier to follow. More than syntax, I really needed to get used to identifying and phrasing the very specific search patterns I needed beyond just "I want this word and this word".
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: Regex ignores caret?

Post by harryray2 »

That's useful..I tried the same for ending with regex:^[$p4]...although it seems to work, it doesn't seem to exclude character after the . in a filename.

eg. testmp4.exe or testmp4 works but not test.mp4
therube
Posts: 4955
Joined: Thu Sep 03, 2009 6:48 pm

Re: Regex ignores caret?

Post by therube »

regex:^[$p4]

That says to find names that start with; a '$', OR a 'P,' OR a '4'.
$money.in.the.bank.TXT
P.is.m4.4.porridge.TXT
4.cloves.of.4m.garlic.TXT

^---note the highlighting that you see with that

regex:.*mp4\.

That says to find anything that has "mp4" in it followed by a dot.
mp4.TXT
jethro.tull.mp4.mp4
mp4.jethro.tull.TXT

regex:.*mp4\....$

Find anything that ends with "mp4", followed by a dot, followed by any three characters (like, say, an extension).
mp4.TXT
mp4.mp4.mp4
mp2mp3mp4.mp4
But not, mp2mp3.mp4.jc


PCRE Regex Cheatsheet
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: Regex ignores caret?

Post by harryray2 »

I'm using it ($) to exclude characters at the end of the filename..it does work, but not if the character is after the . (the file extension)
therube
Posts: 4955
Joined: Thu Sep 03, 2009 6:48 pm

Re: Regex ignores caret?

Post by therube »

You may be using a data set (search) that appears to be returning expected results, but your regex is not doing what you're wanting to do.

Remove any filter & only enter your regex: term & note what is found by that.


Depending on your needs,
suffix:
may very well work for you.
suffix:mp4

Finds mp4 as that end of the name and/or the end of the extension.
tull.mp4
tullmp4.mp4
tullmp4.TXT

suffix:mp4 !ext:mp4

Finds mp4 as the end of the name-part only.
ksad
Posts: 4
Joined: Wed Feb 02, 2022 4:40 pm

Re: Regex ignores caret?

Post by ksad »

So my current understanding is: if I want to look for abc at the beginning of a word, I use ^(abc), and if I want to exclude said letters, I use [^(abc)]. Anything to be excluded has to go inside [^ ].
But apparently square brackets also look at each character literally (except the beginning caret), so a $ doesn't actually stand for "ending", but is a literal dollar sign. I also can't get the dot . to work as a wildcard, it keeps matching literal dots. How do I get the [^ ] to treat what I type into it as regex? Or am I wrong in seeing this as the equivalent of Everything's ! sign?
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Regex ignores caret?

Post by void »

[ ] matches only one character that is in the defined set.

Please try negative lookahead:
regex:^(?!abc)



Using the Everything NOT operator is easier:

!regex:^abc

! = NOT
Post Reply