hgignore regex expression for excluding all files except 1 folder - regex

I'm trying to ignore all .SQL files, except if they are under the DatabaseSchema folder.
This is the regex expression I came up with:
^(?!DatabaseSchema\\).*\.sql$
This seems to work on all the regex testing sites (for example http://regexr.com/ and https://regex101.com/) but when I run it through mercurial it doesn't ignore either of these test files:
DatabaseSchema\test.sql
testRoot.sql
I'm using syntax: glob at the start of my hgignore before switching to regex at the end for this 1 case by using "syntax: regex".
Is there something I'm missing about the way mercurial uses regex in the hgignore file?

Related

Exclude folder except one subfolder via regular expression in Eclipse

I want to add a Resource Filter in Eclipse to exclude a folder named target including all it's files and subfolders except exactly one of this subfolders (target/scala-2.11/classes_managed).
Here is the regex I used for this (including examples for subdirectories):
https://regex101.com/r/aQ2qM1/1
In the referenced example it seems the regex works fine.
However when I apply this regex in Eclipse it does not work.
What's the correct way to write the regex so it works in Eclipse?
Thank you!
You don't need to get all fancy with regular expressions, you can tell eclipse to "Include only" the Folders with a Name matching:
target/scala-2.11/classes_managed
That will exclude all the files that you wish.

File name pattern for ignore files in Mercurial

I use TortoiseHg and I have folders structure, as below:
testSet1
test1
filesystem
input_1.obj
output_1.obj
etalon_1.obj
result_1.obj
test2
filesystem
input_1.obj
output_1.obj
etalon_1.obj
result_1.obj
......
errors.txt
......
result.xml
I need to ignore only .obj files located in directories "testSetN/testN", but not in directories "testSetN/testN/filesystem".
I use glob pattern "*/*/*.obj" in .hgignore, but it doesn't work. Mercurial just ignores all .obj files in all directories (including "filesystem" directory). But if I use, for example, "testSet1/*/*.obj", then everything works fine. How can I do what I need?
It's not necessary for me to use only glob syntax. I would be grateful for any way.
Looking at https://www.selenic.com/mercurial/hgignore.5.html#syntax
Neither glob nor regexp patterns are rooted. A glob-syntax pattern of the form *.c will match a file ending in .c in any directory, and a regexp pattern of the form .c$ will do the same. To root a regexp pattern, start it with ^.
According to this, the glob */*/*.obj will match .obj files inside the filesystem directory, because the glob is not rooted. So it matches those files by rooting the glob at testSetN/
If you have the prefix of testSet on all folders, you can use the glob testSet*/*/*.obj. This way, it will ignore .obj files in a subdirectory of a directory that begins with testSet. - it would also ignore a/testSetX/testY/Z.obj as well as testSetN/testN/N.obj
Mercurial will also let you manually add files that would otherwise be ignored according to .hgignore, so you could simply ignore all .obj files, or use your original glob of */*/*.obj and hg add the files you want to track.
Edit: adding regex as discussed in the comments.
If you prefer regex, or don't have a pattern to root the glob at, you need to use a regex. The regex ^[^/]*/[^/]*/[^/]*\.obj$ to match any .obj file at exactly two levels from the repository root. That is:
^ to anchor the match at the root of the repository
[^/]*/ to match any first-level directory. That is any sequence of characters that does not contain the directory separator /
[^/]*/ again, to match any second-level directory.
[^/]*\.obj$ to match any filenames that end with .obj

Nodemon ignore folder using regex expressions

In Nodemon ignore file I want to selectively ignore the folders from my main folder.
My folder structure is :
-modules
-accounts
-client
-angularfiles
-accounts.js
-repository
-accountrepository.js
-bankbranch
-client
-angularfiles
-bankbranch.js
-repository
-bankbranchrepository.js
In this hierarchy I want to ignore file paths "modules/accounts/client/angularfiles/" &
"modules/bankbranch/client/angularfiles/"
I have many more such modules. In this case I tried writing this regex to ignore based on the expression like so :
/modules\\\w*\\client\\angularfiles\\*/
Using the online regex matcher it matches this path :
\AngularJSApp\modules\accounts\client\angularfiles\bankbranch.js
but nodemon restarts when the file in client\angularfiles is changed.
Nodemon relies on file patterns rather than regular expressions for ignoring some files.
Try this instead:
nodemon --ignore 'modules/**/client/angularfiles/*'

How to hgignore all files of a particular extension except in one directory and its subdirectories?

I would like to use the .hgignore file of Mercurial to ignore all files with file extension .tex, except those .tex files in one particular directory and whatever subdirectory of this directory.
I presume syntax: regexp will be required for this.
A brief explanation of the particular regular expression used, would also be very welcome, so that we can all learn a bit here.
Let's say you want to exclude the directory named exclude. The following regex would then match all files that end in .tex unless exclude/ comes somewhere before that:
^(?!.*\bexclude/).*\.tex$

Regular expression search and replace in multiple files (bulk) - without opening files

I normally use Notepad++ to search and replace what I need (regex), however, I have to open all the files that I need, in order to replace what is needed to be replaced.. My question is how can I do that in bulk (multiple) files, in a folder, without opening any of the files? Is there a good freeware to do that with? or something like creating .bat or .pl file, and run it in the folder to execute the replace? If so, how can it be done?
Simple example:
<b>(\d+\. )</b>
to
\1
This regex removes the bold tag in numbers.
How can it be done for bulk files without using NP++ under Windows?
Use Notepad++'s own Find in files function, that you can find in the Find menu.
This can be done with this perl oneliner:
perl -pi.back -e 's#<b>(\d+\.\d+)</b>#$1#g;' file*
This will process all files that have their name beginning with file and save them before into fileX.back.