Regex and () in directory name
Regex and () in directory name
How to use Regex with brackets in folder names ? When finding duplicates using folder name brackets, Regex rejects the folder.
Re: Regex and () in directory name
regex:"C:\\TMP\\BRU\\7eventy 5ive \(2007\)"
regex:"C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy"
Re: Regex and () in directory name
What if there is a subfolder inside the path with ( ) ?
Re: Regex and () in directory name
Use ^ to match the start of the filename and improve regex performance:
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy"
Use a trailing $ to match the end of the filename:
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)$"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy$"
-or-
Use a trailing \\ to match anything under the specified path
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)\\"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy\\"
without the trailing \\, these searches will match:
C:\TMP\BRU\7eventy 5ive (2007) Backup"
C:\TMP\BRU\7eventy 5ive [2007] - Copy - Copy (2)"
If you are trying to capture the name in the specific path, use:
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)\\([^\\]*$)"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy\\([^\\]*$)"
( ) = capture group.
[^\\] = match any character except \\
* = match previous element zero or more times.
Use \( or \) to match a literal ( or )
[^\\] will also match ( or )
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy"
Use a trailing $ to match the end of the filename:
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)$"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy$"
-or-
Use a trailing \\ to match anything under the specified path
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)\\"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy\\"
without the trailing \\, these searches will match:
C:\TMP\BRU\7eventy 5ive (2007) Backup"
C:\TMP\BRU\7eventy 5ive [2007] - Copy - Copy (2)"
If you are trying to capture the name in the specific path, use:
regex:"^C:\\TMP\\BRU\\7eventy 5ive \(2007\)\\([^\\]*$)"
regex:"^C:\\TMP\\BRU\\7eventy 5ive \[2007\] - Copy\\([^\\]*$)"
( ) = capture group.
[^\\] = match any character except \\
* = match previous element zero or more times.
Use \( or \) to match a literal ( or )
[^\\] will also match ( or )
Re: Regex and () in directory name
Could you give an example with results of
1. Use a trailing $ to match the end of the filename:
2. Use a trailing \\ to match anything under the specified path and without trailing \\
3. Using \\([^\\]*$)"
1. Use a trailing $ to match the end of the filename:
2. Use a trailing \\ to match anything under the specified path and without trailing \\
3. Using \\([^\\]*$)"
Re: Regex and () in directory name
Why not looking on the examples Void gave you one post above your question.
Re: Regex and () in directory name
Please try adding the Regular Expression Match 1 column to see what is being captured.
Experiment with:
regex:^C:\\FolderA\\([^\\]*)$
regex:^C:\\FolderA\\(.*)$
Adjust C:\\FolderA as needed.
Typically ^ will go at the start of your regex search and $ will go at the end to match the whole path and filename.
$1: used with fileexists: is replaced for each file/folder with the value shown in the Regular Expression Match 1 column.
Perl Compatible Regular Expressions
Experiment with:
regex:^C:\\FolderA\\([^\\]*)$
regex:^C:\\FolderA\\(.*)$
Adjust C:\\FolderA as needed.
Typically ^ will go at the start of your regex search and $ will go at the end to match the whole path and filename.
$1: used with fileexists: is replaced for each file/folder with the value shown in the Regular Expression Match 1 column.
Perl Compatible Regular Expressions
Re: Regex and () in directory name
So it seems that this expression matches folders only while,
this expression gives the folder and the file that it contains in the regular expression match 1 column
so the reg exp 1 column1 captures the filename and the subfolder but not just the filename itself...
Re: Regex and () in directory name
The first one should capture just the filename (without path)
The second one should capture the complete path of a file/folder, minus "C:\FolderA\"
The second one should capture the complete path of a file/folder, minus "C:\FolderA\"
Re: Regex and () in directory name
Let's say I wanted to match files from 2 folders in different subfolders at different levels ? and to further complicate things..what if a subfolder has ( ) in them ? will it automatically add \ to subfolder names with ( ) to different levels ?
Re: Regex and () in directory name
I haven't read this thread; just responded on your (then) last post.
Re: Regex and () in directory name
To match subfolders and files, please try the following:
<regex:^C:\\FolderA\\(.*)$ fileexists:C:\\FolderB\\\1> | <regex:^C:\\FolderB\\(.*)$ fileexists:C:\\FolderA\\\1>
(.*) will capture ( and ) without issues.
any ( or ) text replaced with \1 is handled without any issues.
<regex:^C:\\FolderA\\(.*)$ fileexists:C:\\FolderB\\\1> | <regex:^C:\\FolderB\\(.*)$ fileexists:C:\\FolderA\\\1>
(.*) will capture ( and ) without issues.
any ( or ) text replaced with \1 is handled without any issues.
Re: Regex and () in directory name
So, the brackets will be captured within subfolders too ?void wrote: ↑Fri Apr 14, 2023 12:48 am To match subfolders and files, please try the following:
<regex:^C:\\FolderA\\(.*)$ fileexists:C:\\FolderB\\\1> | <regex:^C:\\FolderB\\(.*)$ fileexists:C:\\FolderA\\\1>
(.*) will capture ( and ) without issues.
any ( or ) text replaced with \1 is handled without any issues.
Re: Regex and () in directory name
Yes, ( and ) will be captured with .*
Please make sure you escape any special regex characters in the path that you substitute with C:\\FolderA.
For example:
Instead of C:\FolderA you want to use C:\Program Files (x86)
use the following regex:
regex:"^C:\\Program files \(x86\)"
If unsure, use the following search preprocessor:
regex:^[regexescape:"C:\Program Files (x86)"]
Please make sure you escape any special regex characters in the path that you substitute with C:\\FolderA.
For example:
Instead of C:\FolderA you want to use C:\Program Files (x86)
use the following regex:
regex:"^C:\\Program files \(x86\)"
If unsure, use the following search preprocessor:
regex:^[regexescape:"C:\Program Files (x86)"]
Re: Regex and () in directory name
Thanks I will try this outvoid wrote: ↑Fri Apr 14, 2023 1:31 am Yes, ( and ) will be captured with .*
Please make sure you escape any special regex characters in the path that you substitute with C:\\FolderA.
For example:
Instead of C:\FolderA you want to use C:\Program Files (x86)
use the following regex:
regex:"^C:\\Program files \(x86\)"
If unsure, use the following search preprocessor:
regex:^[regexescape:"C:\Program Files (x86)"]
Re: Regex and () in directory name
Is this supposed to match files inside subfolders with other files in a directory in different level subfolders ? Here is a screenshot ofvoid wrote: ↑Fri Apr 14, 2023 12:48 am To match subfolders and files, please try the following:
<regex:^C:\\FolderA\\(.*)$ fileexists:C:\\FolderB\\\1> | <regex:^C:\\FolderB\\(.*)$ fileexists:C:\\FolderA\\\1>
(.*) will capture ( and ) without issues.
any ( or ) text replaced with \1 is handled without any issues.
U:\regex test folder 1\
U:\regex test folder 1 (brackets)\
When I use the syntax from the above quote into these 2 types of folders then the following results is produced:
<regex:^"U:\\regex test folder 1 (brackets)\\(.*)$" fileexists:"U:\\regex test folder 1\\\1"> | <regex:^"U:\\regex test folder 1\\(.*)$" fileexists:"U:\\regex test folder 1 (brackets)\\\1">