I installed a Sublime plugin called "SublimeOnSaveBuild" which compiles my sass files while saving. But now I'm going to work with more than just one file.
The plugin offers a filter function which is checking if the filename matches the pattern \\.(sass|less|scss)$.
But i need a pattern which matches any file that is not preceded by an underscore.
I tried \\(?!_).*.(sass|less|scss)$ but this doesn't work.
Any ideas what is wrong with this pattern?
The result should be that file.sass gets compiled but not _file.sass.
I assume that this patern should work: ^(?<!_)[a-z-]*\.(sass|less|scss)$
This part: (?<=_) is called positive lookbehind assertion.
You can do some tests here: https://regex101.com/r/gN8uX1/2
As the answer of streetturtle did not work for me, i found another solution on https://joshuawinn.com/ignore-sass-and-less-partials-starting-with-underscore-when-using-sublimeonsavebuild/ which is
(/|\\\\|^)(?!_)(\\w+)\\.(css|js|sass|less|scss)$
Related
Since the auto-generated Django files don't fulfill numerous pylint-requirements, my pre-commit checker fails:
The files look usually like so:
They seem to be located automatically in a sub-folder called "migrations":
Now, I tried to leverage the pre-commit exclude expressions with a proper REGEX.
This one seemed to work on an online REGEX-tester:
[\w-]+\d+[^\\]*.py
Here is the proof:
Now, putting this into my pylint pre-commit checker does unfortunately nothing:
I also tried to just exclude the "migrations" folder, but I could not find a working expression either. How can I make this work?
Use the following to match and exclude all files containing the sub-folder "migrations":
exclude: (migrations)
your regex you tested and the regex you used are different:
# one you tested
[\w-]+\d+[^\\]*.py
# the one you tried
^[\w-]+\d+[^\\]*.py
the ^ anchors to the beginning of the string which is not what you want (your files are specifically in a subdirectory and not at the root of the repository)
additionally, slashes will always be forward slashes for pre-commit's file matching so you should instead exclude (and test against) forward slashes:
[\w-]+\d+[^/]*.py
a minor bug is you'd then match whatever1_py due to an un-escaped . (probably not a problem but here's an improvement):
[\w-]+\d+[^/]*\.py
you're also using a javascript regex tester -- while it doesn't matter for the features you're using here you probably want to use a python one as the patterns here are python regular expressions
so try this:
exclude: '[\w-]+\d+[^/]*\.py'
disclaimer: I wrote pre-commit, though it matters less here since this is just a regex confusion
I would need a regex to match my files named "something".Title"numberFrom1to99".mp4 on Windows' File Explorer, my first approach as a regex newbie was something like
"..mp4"
, but it didn't work, so i tried
"*.Title[1-9][0-9].mp4"
, that also did not work.
I would also like a tip on how to search regex related advices on Stackoverflow archive but also on the web, so that i can be specific, but without having the regex in the searching bar interact.
Thank you!
EDIT
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)
Try something like this:
(.*)\.[A-za-z]+\d+\.mp4
See this Regex Demo to get an explanation on the regex.
Use regex101.com to test your regexs
Here it is:
^[\s\S]*\.Title[1-9][0-9]?\.mp4$
I suggest regexr.com to find many interesting regexes(Favourites tab) and simple tutorial.
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)
My college asked my to provide him with a regex that only matches if the test-string endswith
.rar or .part1.rar or part01.rar or part001.rar (and so on).
Should match:
foo.part1.rar
xyz.part01.rar
archive.rar
part3_is_the_best.rar
Should not match:
foo.r61
bar.part03.rar
test.sfv
I immediately came up with the regex \.(part0*1\.)?rar$. But this does match for bar.part03.rar.
Next I tried to add a negative look behind assertion: .*(?<!part\d*)\.(part\0*1\.)?rar$ That didn't work either, because look around assertions need to be fixed width.
Then I tried using a regex-conditional. But that didn't work either.
So my question: Can this even be solved by using pure regex?
An answer should either contain a link to regex101.com providing a working solution, or explain why it can't work by using pure regex.
You could use lookahead to verify the one case that fails your original regex (.rar with .part part that isn't 0*1) is discredited:
^(?!.*\.part0*[^1]\.rar$).*\.(part0*1\.)?rar$
See it in action
This is an old question, but here's another approach:
(?:\.part0*1\.rar|^(?<!\.)\w+\.rar)$
The idea is to match either:
A string that ends with .part0*1.rar (ie foo.part01.rar, foo.part1.rar, bar.part001.rar), OR
A string that ends with .rar and doesn't contain any other dots (.) before that.
Works on all your test cases, plus your extra foo.part19.rar.
https://regex101.com/r/EyHhmo/2
I'm trying to use the Atomiq tool to check only one file for duplicate code. However there is only a regex exclusion option.
I've tried using .*(?!filename) to exclude all negative results which doesn't work. Does anybody have an idea?
Try following regex to get your result
(.*)filename
I use empty .hg_keep files to keep some (otherwise empty) folders in Mercurial.
The problem is that I can't find a working regex which excludes everything but the .hg_keep files.
lets say we have this filestructure:
a/b/c2/.hg_keep
a/b/c/d/.hg_keep
a/b/c/d/file1
a/b/c/d2/.hg_keep
a/b/.hg_keep
a/b/file2
a/b/file1
a/.hg_keep
a/file2
a/file1
and I want to keep only the .hg_keep files under a/b/.
with the help of http://gskinner.com/RegExr/ I created the following .hgignore:
syntax: regexp
.*b.*/(?!.*\.hg_keep)
but Mercurial ignores all .hg_keep files in subfolders of b.
# hg status
? .hgignore
? a/.hg_keep
? a/b/.hg_keep
? a/file1
? a/file
# hg status -i
I a/b/c/d/.hg_keep
I a/b/c/d/file1
I a/b/c/d2/.hg_keep
I a/b/c2/.hg_keep
I a/b/file1
I a/b/file2
I know that I a can hd add all the .hg_keep files, but is there a solution with a regular expression (or glob)?
Regexp negation might work for this. If you want to ignore everything except the a/b/.hg_keep file, you can probably use:
^(?!a/b/\.hg_keep)$
The parts of this regexp that matter are:
^ anchor the match to the beginning of the file path
(?! ... ) negation of the expression between '!' and ')'
a/b/\.hg_keep the full path of the file you want to match
$ anchor the match to the end of the file path
The regular expression
^a/b/\.hg_keep$
would match only the file called a/b/.hg_keep.
Its negation
^(?!a/b/\.hg_keep)$
will match everything else.
Not quite sure in what context you are using the Regex but this should be it, this matches all lines ending in .hg_keep:
^.*\.hg_keep$
EDIT: And here is a Regex to match items not matching the above expression:
^(?:(?!.*\.hg_keep).)*$
Try (?!.*/\.hg_keep$).
Looking for something similiar to this.
Found an answer, but it's not what we want to hear.
Limitations
There is no straightforward way to ignore all but a set of files. Attempting to use an inverted regex match will fail when combined with other patterns. This is an intentional limitation, as alternate formats were all considered far too likely to confuse users to be worth the additional flexibility.
Ref: https://www.mercurial-scm.org/wiki/.hgignore