Regex ignores caret?
Regex ignores caret?
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.
Re: Regex ignores caret?
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
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' ) 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
^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
Good choice!
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' ) 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
Re: Regex ignores caret?
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".
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".
Re: Regex ignores caret?
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
eg. testmp4.exe or testmp4 works but not test.mp4
Re: Regex ignores caret?
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
Re: Regex ignores caret?
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)
Re: Regex ignores caret?
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, may very well work for you.
Finds mp4 as that end of the name and/or the end of the extension.
tull.mp4
tullmp4.mp4
tullmp4.TXT
Finds mp4 as the end of the name-part only.
Remove any filter & only enter your regex: term & note what is found by that.
Depending on your needs,
suffix:
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.
Re: Regex ignores caret?
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?
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?
Re: Regex ignores caret?
[ ] 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
Please try negative lookahead:
regex:^(?!abc)
Using the Everything NOT operator is easier:
!regex:^abc
! = NOT