Where do I place my regex to search for files? + how to post questions properly

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
marceepoonu
Junior Member
Junior Member
Posts: 5
Joined: 2009-08-19, 17:34 UTC
Location: Los Angeles, California
Contact:

Where do I place my regex to search for files? + how to post questions properly

Post by *marceepoonu »

I want to use the following Regular-Expression to search for files:

Code: Select all

((.+?)?(?=\.vbs))(.vbs)$
The Regular-Expression works just fine in Regex Buddy as shown in this image:
Image: https://drive.google.com/file/d/1-7JXmmEoporWg0WTAUXFNtY1DMlWItOV/view?usp=sharing

But when I tried to run that Regular-Expression in a Total Commander search window, I got an error message, as shown in this image:
Image: https://drive.google.com/file/d/1-37IAMZahvqZwvNcDwTCJ4_3FJPxnQYP/view?usp=sharing

Where should I be placing my Regular-Expression?
Marc Hankin
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6495
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *Horst.Epp »

That works enabling Everything and using its syntax in TC search for.
Global search

Code: Select all

ev:regex:((.+?)?(?=\.vbs))(.vbs)$
or search in current TC dir

Code: Select all

ed:regex:((.+?)?(?=\.vbs))(.vbs)$
Windows 11 Home x64 Version 23H2 (OS Build 22631.3527)
TC 11.03 x64 / x86
Everything 1.5.0.1373a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *DrShark »

Horst.Epp wrote: 2019-11-09, 18:10 UTCThat works enabling Everything and using its syntax in TC search for.
I haven't used Everything yet, and have a question: so TC and Everything RegEx syntax is different? Which one is more powerful?
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6495
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *Horst.Epp »

DrShark wrote: 2019-11-11, 07:08 UTC
Horst.Epp wrote: 2019-11-09, 18:10 UTCThat works enabling Everything and using its syntax in TC search for.
I haven't used Everything yet, and have a question: so TC and Everything RegEx syntax is different? Which one is more powerful?
Everythings Regex Syntax from its help

Code: Select all

Regex Syntax:
a|b	Matches a or b
gr(a|e)y	Matches gray or grey
.	Matches any single character
[abc]	Matches a single character a, b or c
[^abc]	Matches any single character except a, b or c
[a-z]	Matches a single charactor in the range a to z
[a-zA-Z]	Matches a single charactor in the range a to z or A to Z
^	Matches the start of the filename
$	Matches the end of the filename
( )	Defines a marked subexpression
\n	Matches what the nth marked subexpression matched, where n is a digit from 1 to 9
\b	Match word boundaries
*	Matches the preceding element zero or more times
?	Matches the preceding element zero or one times
+	Matches the preceding element one or more times
*?	Lazily matches the preceding element zero or more times
+?	Lazily matches the preceding element one or more times
{x}	Matches the preceding element x times
{x,}	Matches the preceding element x or more times
{x,y}	Matches the preceding element between x and y times
\	Escape special character
TCs Regex from the help:

Code: Select all

Regular expressions
 
Regular expressions are a very powerful search tool. They allow to search for complex classes of words. Regular expressions are mainly meant for professionals, but can also be useful in the office for finding certain documents (see examples below).
 
Total Commander supports regular expressions in the following functions:
- Commands - Search (in file name and file contents)
- In Lister
- In the Multi-Rename tool
- In the selection dialog
 
Regular expressions consist of normal characters and special characters, so-called meta-characters. The following characters are meta-characters or initial parts of meta-characters:
.  \  (  )  [  ]  {  }  ^  $  +  *  ?    (only in character classes: - )
 
Normal characters:
 
test finds the string "test" in the searched text. Note: This finds "test" ANYWHERE in a file name or on a line in text.
 
Escape sequences:
 
A backslash \ starts an Escape sequence. Examples for escape sequences:
\t Tabstop
\xnn Character with hexadecimal code nn. Example: \x20 is the space character. The character table charmap.exe (if installed) shows the character code of most special characters. You can use the Windows calculator in scientific mode to convert from decimal to hex.
\x{nnnn}
Unicode character with hexadecimal code nn. Note that Total Commander now uses Unicode for file names, so you need to use this notation for characters other than basic English.
\[ Left square bracket. Since the square brackets are meta-characters, they need to be written as \[ to search for them in the target string.
\\ Finds a backslash.
\. Finds a dot ("." alone finds any character, see below).
 
Character classes
 
Characters in square brackets build a character class. It will find exacly one character from this class. A dash allows to define groups, e.g. [a-z]. A ^ at the beginning finds all characters except for those listed.
Examples:
[aeiou] Finds exactly one of the listed vowels.
[^aeiou] Finds everything except for a vowel.
M[ae][iy]er Finds a Mr. Meier in all possible ways of writing: Mayer, Meyer, Maier, Meier. Very useful if you cannot remember the exact writing of a name.
 
Meta-characters
 
Here is a list of the most important meta-characters:
^ Line start
$ Line end
. Any character
\w a letter, digit or underscore _
\W the opposite of \w
\d a digit
\D no digit
\s a word separator (space, tab etc)
\S no word separator
\b finds a word boundary (combination of \s and \S)
\B the opposite of \b
 
Iterators
 
Iterators are used for a repetition of the character or expression to the left of the iterator.
* zero or more occurrences
+ one or more occurrences
{n} exactly n occurrences
{n,} at least n occurrences
{n,m} at least n and max. m occurrences
All these operators are "greedy", which means that they take as many characters as they can get. Putting a question mark ? after an operator makes it "non-greedy", i.e. it takes only as many characters as needed.
Example: "b+" applied to the target string "abbbbc" finds "bbbb", "b+?" finds just "b".
 
Alternatives
 
Alternatives are put in round brackets, and are separated by a vertical dash.
Example: (John|James|Peter)  finds one of the names John, James or Peter.
 
Subexpressions for search+replace
 
Text parts in round brackets are taken as subexpressions. Up to 32 subexpressions are supported now.
Example: To swap the title and interpret in the file name of an mp3 file, when they are separated by a dash (Title - Interpret.mp3), use the following options:
Search for: (.*) - (.*)\.mp3
Replace by: $2 - $1.mp3
Here $1 means the text in the first round bracket, and $2 the text in the second round bracket.
New: In "Replace by", use parameters \U, \L, \F, \n to convert from this point on to uppercase, lowercase, first char in word uppercase, and back to unchanged, e.g.
Search for: (.*) - (.*)\.mp3
Replace by: \U$2 - \L$1.mp3
 
Backreferences
 
\n Finds subexpression n another time in the search result.
Example: (.+)\1+  finds e.g.  abab  (where the first ab is found by .+  and the second by \1+ )
 
Modifiers

Modifiers are used for changing behaviour of regular expressions.
 
(?i) Ignore Upper-/lowercase. In Total Commander, this is the default for file names.
(?-i) Case-sensitive matching.
(?g) Switches on "greedy" mode (active by default)
(?-g) Turns off "greedy" mode, so "+" means the same as "+?"
 
The other modificators are not relevant for Total Commander, because the program only supports searching within one line.
 
Total Commander uses the free Delphi library TRegExpr by Andrey V. Sorokin, available on http://www.regexpstudio.com/ 
Some of the above explanations are from the help file for this library.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3527)
TC 11.03 x64 / x86
Everything 1.5.0.1373a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Where do I place my regex? RE RegExp Regular-Expression TRegExpr by Andrey V. Sorokin

Post by *Stefan2 »

marceepoonu wrote: 2019-11-09, 17:33 UTCwhen I tried to run that Regular-Expression
in a Total Commander search window, I got an error message,

Open the search and press the F1 key.
Scroll down till "RegEx        Search in file names using regular expressions."
Click at "regular expressions." and read which syntax TC uses and support.

Total Commander uses the free Delphi library TRegExpr by Andrey V. Sorokin,
available on http://regexpstudio.com/TRegExpr/Help/regexp_syntax.html
Syntax can also be found at http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html
or http://www.den4b.com/wiki/ReNamer:Regular_Expressions



marceepoonu wrote: 2019-11-09, 17:33 UTCWhere should I be placing my Regular-Expression?
Write your regex just in the "Search for:" box and check the [x]RegEx option.




Note, there is also "[WDX] PCREsearch"-plugin by *milo1012 » Fri Sep 13, 2013
based on Perl Compatible Regular Expressions (PCRE) library
https://www.ghisler.ch/board/viewtopic.php?t=38098





HTH :D
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *tuska »

'Everything' uses the Perl Compatible Regular Expressions (PCRE) engine.
['Everything': Menu "Help" - "About Everything CTRL+F1" - "License"]

See also:
PCRE - Perl Compatible Regular Expressions
Perl 5 regular expression syntax


Windows 10 Pro (x64) Version 1903 (OS build 18362.449)
TC 9.50ß4 x64/x86 | Everything - Version 1.4.1.955 (x64)
☑ 'Everything' | How to use TC <=> Everything
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *Ovg »

2DrShark

TC regex engine doesn't support lookahead and lookbehind
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
marceepoonu
Junior Member
Junior Member
Posts: 5
Joined: 2009-08-19, 17:34 UTC
Location: Los Angeles, California
Contact:

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *marceepoonu »

I do not know what I am doing wrong. The following image shows what I do that triggers the error message, and I don't know what I'm not doing that I should be doing. Here's the image: Image: https://drive.google.com/file/d/1usEqsq4tOFBwZ4lsl1ne0dKKtP_PmfA7/view?usp=sharing
Marc Hankin
User avatar
petermad
Power Member
Power Member
Posts: 14808
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *petermad »

2marceepoonu
Help:
Modifiers are used for changing behaviour of regular expressions.

(?i) Ignore Upper-/lowercase. In Total Commander, this is the default for file names.
(?-i) Case-sensitive matching.
(?g) Switches on "greedy" mode (active by default)
(?-g) Turns off "greedy" mode, so "+" means the same as "+?"
I think that: (?=\.vbs) is considered a modifier by TC, but only the modifiers here above are allowed.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *Ovg »

2marceepoonu
2petermad
(?=\.vbs) - lookahead. Searching for something is followed by literal .vbs
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
marceepoonu
Junior Member
Junior Member
Posts: 5
Joined: 2009-08-19, 17:34 UTC
Location: Los Angeles, California
Contact:

Re: Where do I place my regex? RE RegExp Regular-Expression TRegExpr by Andrey V. Sorokin

Post by *marceepoonu »

Stefan2 wrote: 2019-11-11, 09:10 UTC
marceepoonu wrote: 2019-11-09, 17:33 UTCwhen I tried to run that Regular-Expression
in a Total Commander search window, I got an error message,
marceepoonu wrote: 2019-11-09, 17:33 UTCWhere should I be placing my Regular-Expression?
Write your regex just in the "Search for:" box and check the [x]RegEx option.

Note, there is also "[WDX] PCREsearch"-plugin by *milo1012 » Fri Sep 13, 2013
based on Perl Compatible Regular Expressions (PCRE) library
https://www.ghisler.ch/board/viewtopic.php?t=38098


HTH :D

I installed the "[WDX] PCREsearch"-plugin.
Then, I opened the Find Files window in TC.
Then I opened the Plugins Tab, and (as this image Image: https://drive.google.com/file/d/17bchFMFGR958oClgbB3jsW8vTuu0Elbd/view?usp=sharing shows), in the Plugins tab I:
1. Clicked the "Search in plugins" box;
2. Selected the "AND" radio button (which I do not understand, and I wish I knew where to find an explanation of its operation); and
3. Selected "pcresgareh" in the Plugin column (as shown in this image Image: https://drive.google.com/file/d/17bchFMFGR958oClgbB3jsW8vTuu0Elbd/view?usp=sharing).

Next, I formulated this regular expression search in RegexBuddy, using the PCRE 8.39 UTF-32 flavor regular expressions.
This image Image: https://drive.google.com/file/d/17bchFMFGR958oClgbB3jsW8vTuu0Elbd/view?usp=sharing shows that the regular expression matches the highlighted files located in the directory "E:\Apps\UtilitiesByMarc", according to RegexBuddy.

Lastly, I selected the General tab in TC, and then I clicked the "Start search" button
But as this image Image: https://drive.google.com/file/d/17bchFMFGR958oClgbB3jsW8vTuu0Elbd/view?usp=sharing reflects, TC's "Search results" window shows "[No files found]"

So I'm no longer getting an error message, but my question now is what do I need to do differently, so that I can search for files in that directory (E:\Apps\UtilitiesByMarc) using the regular expression below, which is an acceptable search in the PCRE 8.39 UTF-32 flavor of regular expressions?
((.+?)?(?=\.vbs) ) ( .vbs) $
Marc Hankin
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Re: Where do I place my regex to search for files? + how to post questions properly

Post by *Ovg »

It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
Post Reply