Regex matching a dll but not the directory - regex

I have a conf file that is loading plugins. I need to parse and match a certain plugin in a directory but not others in the same directory:
plugin: c:\program files\application\abc\abc.dll
plugin: c:\program files\application\abc\xyz.dll
I need to match the abc.dll only but due to the fact that the abc is also in the dir name, it matches both lines but I dont want xyz.dll
So I tried:
^plugin:(.*)(abc.dll)
So ^ = start of line, then plugin, then .* anything, then abc escape dot dll.
But it doesnt seem to work. Can anyone help please?

The problem is the dot in abc.dll. Try escaping it so it's not a wild card.
^plugin:(.*)(abc\.dll)

You would like to use this regexp:
([a-zA-Z0-9-_]*\.dll)
Here is example

Related

hgignore regex expression for excluding all files except 1 folder

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?

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

hg: how to exclude "*.xll" file but not xll directory

In my .hgignore file, I am trying to ignore all generated xll files. I (unfortunately) have a directory called "xll" within the domain of the repository, and I do not want to ignore the directory itself.
I have tried:
syntax: regex
\.xll$
which I thought should mean "match all that ends in '.xll'"
and
syntax: regex
*.\.xll$
which I thought should mean "match all that have at least one arbitrary character, followed by '.xll'".
With either of the above, the directory is not ignored (yay) but neither is a file foobar.xll (darn). If I use a bare "xll" with regex, or "*.xll" with glob, both the directory and the file are ignored.
This is in linux (Ubuntu 10.04.4) with hg 2.6 (TortoiseHG 2.8) (I'm observing the effect in Nautilus via the presence or absence of "X" icons).
Thanks in advance!
EDIT
(adding comments in here as they are too long to fit in a comment...)
Thanks for all the responses. Turns out I was misinterpreting some things. So:
- because I used "regex" instead of "regexp" (and I had "glob" at top of file), whatever I put on the line that referred to "xll" was being interpreted by "glob", so the line did have an effect (which made me think, incorrectly, that the "syntax: regex" line was doing what I thought it was
- by coincidence, all the files in my "xll" directory were filtered out (as they should have been) by other lines in .hgignore, and not by the "*.xll" line
- consequently, in Nautilus, the xll directory was marked as "ignored", not because the filter ignoring the entire directory, but instead because other filters were filtering all files within that directory
Bottom line, the *.xll I had under "syntax: glob" was actually filtering out files exactly as desired. The feedback in Nautilus was just different than I expected.
It's .*\.xll$, not *.\.xll$.
Using glob syntax works well for me:
syntax: glob
*.xll
When I create a directory named xll with an untracked file, I still see the file in the output from hg status:
$ mkdir xll
$ touch a.xll x.txt xll/b.xll xll/y.txt
$ echo 'syntax: glob\n*.xll' > .hgignore
$ hg status
? .hgignore
? x.txt
? xll/y.txt
Using \.xll$ with syntax: regexp also works great for me.

.hgignore syntax for ignoring only files, not directories?

I have a problem which I can't seem to understand. I'm using TortoiseHg (version 0.7.5) on Windows but on Linux I have the same problem. Here it is:
My .hgignore file:
syntax: regexp
^[^\\/]+$
What I'm trying to achieve is to add to the ignore list the files which are in the root of the hg repository.
For example if I have like this:
.hg
+mydir1
+mydir2
-myfile1
-myfile2
-anotherfile1
-anotherfile2
.hgignore
I want myfile1(2) and anotherfile1(2) to be ignored (names are only for the purpose of this example - they don't have a simple rule that can be put in the hgignore file easily)
Is there something I'm missing because I'm pretty sure that regexp is good (I even tested it)? Ideas?
Is there a simpler way to achieve this? [to add to the ignore list files that are in the root of the mercurial repository]
I relayed this question in #mercurial on irc.freenode.net and the response was that you cannot distinguish between files and directories — the directory is matched without the slash that you're searching for in your regexp.
However, if you can assume that your directories will never contain a full-stop ., but your files will, then something like this seems to work:
^[^/]*\..*$
I tested it in a repository like this:
% hg status -ui
? a.txt
? bbb
? foo/x.txt
? foo/yyy
Adding the .hgignore file gives:
% hg status -ui
? bbb
? foo/x.txt
? foo/yyy
I .hgignore
I a.txt
which indicates that the a.txt file is correctly ignored in your root directory, but x.txt in the foo subdirectory is not. You can also see that a file named just bbb in the root directory is not ignored. But maybe you can add such files yourself to the .hgignore file.
If you happen to have a directory like bar.baz in your root directory, then this directory and all files within will be ignored. I hope this helps a bit.
Here is a dirty trick:
Create an empty file ".hidden" in your directory, than add to .hgignore:
^mydir/(?!\.hidden).+$
This will ignore all files in the directory except ".hidden".