## Regex: \ or \\

General discussion related to "Everything".
Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Regex: \ or \\

Is there a place to make an option that Regex will treat a single \ as literal \ instead of \\
the Regex will be applyed only in these parts \<regex>\<regex>
?

Or maybe to wrap the functions part with a code design, so that the user will be able to type:
\
Ctrl+R
In Directory Regex
Ctrl+R
\
Ctrl+R
Filename Regex

\In Directory Regex\Filename Regex

\ = Literal
Last edited by Stamimail on Thu Jun 07, 2018 8:08 am, edited 1 time in total.

void
Posts: 5922
Joined: Fri Oct 16, 2009 11:31 pm

### Re: Regex: \ or \\

What about disabling regex from the search menu and using the regex: modifier.

This will allow you to search paths with a single \ and then use the regex: modifier to match your regular expression.
eg: "c:\program files\" regex:^foo.*bar

-or-

maybe another modifier "noescape:" could be added to treat \ as \\
noescape:regex:"c:\program files\^foo.*bar"

Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Re: Regex: \ or \\

noescape:regex:"c:\program files\^foo.*bar"
I don't remember the regex syntax well, but I think the better solution will be to use a new brackets code. like:
{c:\program files\}^foo.*bar
(?$$c:\program files$$)^foo.*bar
^{c:\program files\} foo.*bar

Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Re: Regex: \ or \\

Code: Select all

c:\\program files (x86)\\
The same problem for () ?
() are using for goruping.
Needs to use $$x86$$ isn't it?

1. Is there no regex method how to have a literal string?
2. Another question,
noescape:regex:"c:\program files\^foo.*bar"
What is the meaning of ^ in this query?

I assumed that when MatchPath is enabled, the FullPath is the TextBeingSearched, and when MatchPath is disabled, Filename is the TextBeingSearched.
?

void
Posts: 5922
Joined: Fri Oct 16, 2009 11:31 pm

### Re: Regex: \ or \\

1. Is there no regex method how to have a literal string?
Not without escaping AFAIK.
What is the meaning of ^ in this query?
^ matches the start of the filename.
I should of used the following example:
noescape:regex:"^c:\program files\foo.*bar"

noescape:regex:"c:\program files\^foo.*bar" will never match anything..
I assumed that when MatchPath is enabled, the FullPath is the TextBeingSearched, and when MatchPath is disabled, Filename is the TextBeingSearched.
?
Correct, however, including a \\ in your search will also enable full path matching.

What about using / instead of \\ ?

Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Re: Regex: \ or \\

What about using / instead of \\ ?
In this way, the user will still need to replace each "\" in the path to "/".
The whole thing, is to save from the user this need of replacing all "\" in a long path.

It will be good to ask a regex expert for a suggestion.

therube
Posts: 2816
Joined: Thu Sep 03, 2009 6:48 pm

### Re: Regex: \ or \\

NotNull
Posts: 2572
Joined: Wed May 24, 2017 9:22 pm

### Re: Regex: \ or \\

I don't get this magic stuff .. Could you give an example?

@Stamimail: if this 'magic' doesn't hepl, things could get difficult as the "\" is perl regex's 'escape character'. For example: \s is used to indicate a space (" ") and \d to indicate a digit (0-9).
So if you entered regex:c:\special\directory , you will get unexpected results.

But I'm not a regex expert, so there may be other options

void
Posts: 5922
Joined: Fri Oct 16, 2009 11:31 pm

### Re: Regex: \ or \\

I think Stamimail wants an easy way to paste a long path into a regex formula without the need to manually escape each \

eg:

would have to be converted to:

when something like the following could be used to escape the whole thing:

-or-

-or-

Another option is to improve the pasting into the search edit when there is an active regex: modifier or when regex is enabled from the Search menu, if a path is detected the slashes could be escaped automatically.

Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Re: Regex: \ or \\

It is not so convenient like open and close parentheses but...
I think this is what I was looking for:

Consider to add this as a tip to help.

NotNull
Posts: 2572
Joined: Wed May 24, 2017 9:22 pm

### Re: Regex: \ or \\

Very nice catch, Stamimail!

void
Posts: 5922
Joined: Fri Oct 16, 2009 11:31 pm

### Re: Regex: \ or \\

Nice find.
Works well until there's a \E in the path.
eg: \QC:\Program Files\Everything\E would break at the first \E

I've added a single \ to enable match path when in \Q \E for the next release of Everything.

Stamimail
Posts: 756
Joined: Sat Aug 31, 2013 9:05 pm

### Re: Regex: \ or \\

void wrote:Works well until there's a \E in the path.
eg: \QC:\Program Files\Everything\E would break at the first \E
Thank you for bringing this to attention.
It turns out that using \Q \E is not so a good tip.

Still, as far as it's worth it, we can think about choosing a character/s from these, as a replacement for \Q \E

NotNull
Posts: 2572
Joined: Wed May 24, 2017 9:22 pm

### Re: Regex: \ or \\

Without thinking this through: I suggest using double-double qutoes, like regex:""C:\Path\To\Everything.ini""

That way. if this "" is detected by Everything. the query-parser can change the complete path to lowercase (filenames are case-retentive but not case-sensitive on Windows) and wrap in \Q \E, resulting in this regular expression to be executed:

regex:\Qc:\path\to\everything.ini\E

RegexNinja
Posts: 18
Joined: Sat Apr 11, 2020 2:45 pm
Location: OrionCygnusArm, MilkyWay

### Re: Regex: \ or \\

For an easy way to put regex-converted FolderPaths into the search-box:
I wrote a batch that lets you right-click a folder, choose 'RegexInEverything' to do just that.
You just need to create a reg-key that points to the batch's location, & you're good to go:
There's only 2 files you need to create:

Batch file:
@echo off
Set epath=%1
SetLocal EnableDelayedExpansion
::
:: Convert 11 Regex Specials ----> \Literals
For %%A IN (\,^^,^(,^),{,},[,],+,.,\$) DO Set epath=!epath:%%A=\%%A!
::
:: Uncomment NextLine before adding NonUnicode-compliant commands (? --> .*)
:: Set epath=!epath:?=.*!
::
:: Run Everything with regex:"expression" in SearchBox
Start "" "C:\PortableApps\Everything\1.3.0.632b\Everything.exe" -noregex -s regex:"""!epath!"""
::
:: Uncomment NextLine if you prefer enabling regex (versus regex:"expression")
:: Start "" "C:\PortableApps\Everything\1.3.0.632b\Everything.exe" -regex -s !epath!

Edit the paths to reflect the FullPathName to your Everything.exe
Then save it to somewhere like: C:\Bats\RegInEvr.bat

Reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\RegexInEverything]
[HKEY_CLASSES_ROOT\Folder\shell\RegexInEverything\command]
@="\"C:\\Bats\\RegInEvr.bat\" \"%1\""

Edit the path to reflect your batch's FullPathName.. Note how \\ represents the directory-separators.
Edit RegexInEverything if you wanna change the text that appears when right-clicking a folder.
Add one extra blank-line in the file, and save it with the .reg extension..
Then just right-click it, and select Merge to create the reg-key.

After that, you can right-click a folder to show the regex-formatted DirPath in Everything's search box.
Cheers.
Last edited by NotNull on Wed May 27, 2020 12:46 pm, edited 2 times in total.
Reason: ... and revert those changes due to tags in code.

NotNull
Posts: 2572
Joined: Wed May 24, 2017 9:22 pm

### Re: Regex: \ or \\

Nice!

I haven't tested your script (yet), but this:
RegexNinja wrote:
Sun May 24, 2020 9:32 am
:: Uncomment NextLine before adding NonUnicode-compliant commands (? --> .*)
:: Set epath=!epath:?=.*!
is probably caused by limited unicode support in CMD. CMD works with codepages, a country/language dependent subset.
You can probably accept/support a "fake ?" in your script by adding a
CHCP 65001
command in the beginning of your script.

(and as a ? represents one character in CMD, you can also replace it with a single
.
instead of ".*". Or am I missing something here?)

RegexNinja
Posts: 18
Joined: Sat Apr 11, 2020 2:45 pm
Location: OrionCygnusArm, MilkyWay

### Re: Regex: \ or \\

Hi.. As written, there's no problem with unicode filenames.
I threw the comment in there for others, incase they wanted to do something else with the converted-string.
It's really just a warning.. You never know how someone will take a batch, & mod it to suit their own needs.

Dont quote me on this, but I believe cmd converts some unicodes into ? and others into ??
I think it depends on how 'high' of a unicode it is.. The cmd-version might also be a factor.
I'd have to do some testing to know for sure, so I just threw .* in there as a catch-all.

If ? and ?? are the only possible cmd auto-conversions, then a better batch-conversion would be .{0,1}
It's an ugly conversion anyway you look at it, not very reliable.. Still much better than .* though!
I'll edit the comments accordingly, if someone can please verify ? and ?? as the only possibilites.
Cheers!

NotNull
Posts: 2572
Joined: Wed May 24, 2017 9:22 pm

### Re: Regex: \ or \\

While cleaning out my RAM drive, i found this, based on RegexNinja's work:

It will copy a filename as regex to the clipboard, including the regex: that Everything uses.
Example: SHIFT-rightclick "C:\Program Files (x86)" in Explorer or similar program and choose Copy path as regex
Pasting in Everything's search bar then will show regex:"C:\\Program Files $$x86$$"

To install: double-click CopyPathAsRegex.cmd
To uninstall: double-click CopyPathAsRegex.cmd again

CopyPathAsRegex.zip