BrunchJS joinTo parent directory (brunch-config.coffee) - regex

I would like to get assets from a parent directory in a joinTo like this :
exports.config =
paths:
public: './../public'
compass: './config.rb'
watched: ['app']
files:
javascripts:
joinTo:
'/js/master.js':/^(../../../directory/target|app[\/\\]public)/
My problem come from this ../../../directory/target to up one or more directory.
But it seem impossible, because BrunchJS use Regex to find directory.
There is a way to do what i wish?
Thanks

Not sure I completely understand your question or description of what's going wrong. Or even quite what you're trying to match with that regex - is app a sibling of target, or local to cwd?
But you don't need to use a single regex. You may find it much easier to use a glob pattern or an array of globs/regexes/paths such as
files:
javascripts:
joinTo:
'js/master.js': [
'../../../directory/target/**/*',
'app/public/**/*'
]
Take a look at the Brunch joinTo documentation and anymatch documentation.
You also need to watch out for that leading slash in your target file, which may get interpreted as an absolute path.

Related

Write regex for path changes in VSCode

At work, I often have to change the paths of files. For example, there is:
qwerty123/aasdad/index.js
qwerty321/ewqewe/script.js
I need to replace it with
js/index.js
There are also pictures and css files. They are always in the img and css folders. So I couldn't get it right. My mind was not enough =( Changing paths for this small task takes about 10 minutes, it's a pity to spend them on this.
Tried this:
src="(.*)" ".*/(.+)\.jpg"
but it also cuts out the file name, but I need it.
Find: [^\s]*\b(\/.*\.js\b)
Replace: js$1
If your paths have spaces in them the find regex won't work as the demo shows!
See Rege101 demo

give sudo permission to log files on different paths like /a/b1/c.log and /a/b2/d.log etc. files

I need a nice column for Centrify tool which include all the log files under the different folders, for example;
/oradata1/oracle/admin/A/scripts/rman_logs/*.log
/oracle/oracle/admin/B/scripts/rman_logs/*.log
/oradata2/admin/C/scripts/logs/*.log
I used this but after the * character user can see all logs;
/ora(data(1|2)|cle)/oracle|admin/admin/*/scripts/rman_logs
/ora(data(1|2)|cle)/oracle|admin/admin/*/scripts/rman_logs
Which expression I must use.
If I understandy our question correctly, you want only .log files. You can use a positive lookahead to assert that it is indeed a log file (contains .log at the end of filename), and match the filename whatever it is (.*).
Then it's really easy. (?=.*\.log(?:$|\s)).* Of course, you can also add specific folders if you wish to restrict the matches, but the positive lookahead will still do its work. I.e. (?=.*\.log(?:$|\s)).*/scripts/.*
EDIT: As your comment, you only need those folders, so you just specify their filepaths in alternations and add [^.\s\/]*\.log at the end. So:
(?:\/oradata1\/oracle\/admin\/A\/scripts\/rman_logs\/|\/oracle\/oracle\/admin\/B\/scripts\/rman_logs\/|\/oradata2\/admin\/C\/scripts\/logs\/)[^\s.\/]*\.log You may shorten the regex by trying to combine filepath elements, but, imo, not necessary as you might as well specify each filepath individually, if they don't overlap too much.
I have found a global expression.
this is not a good way but it works and save me from lots of job. The main files are under the ....../scripts/rman_logs/ for all servers so I use this way.
I can produce these lines and can be a command group for users so this works good
tail /////scripts/rman_logs/*.log
tail ////scripts/rman_logs/.log
Thanks for your helps.

Matching file extensions - regex nodejs

I'm currently running a regular expression in a node file that's designed to copy my custom fontello icon font files across to the public directory. To ensure I'm not copying irrelevant files I'm using the following:
var match = new RegExp(/\.(woff|svg|ttf|eot)/g);
if (match.test(fileName)) {
// Do something
}
As I cycle through the fonts available, the only two that are being matched are
app.svg
app.eot
The app.ttf and app.woff files are not matching the expression.
I have tried out the expression over at http://www.regexr.com/ and it appears to work for my purposes. Keep in mind that I don't require much more stringent testing than this as there is only a handful of files in that directory.
If anybody can give me some guidance I would be most appreciative.
Your regex is correct.Tried it.
See

gitignore all files except all java files in subdirectory

I've tried a bunch of different methods.
1.
*
!.gitignore
!./src/com/AleXander/*
2.
/*
!.gitignore
!src/com/Alexander/*.java
3.
*
!.gitignore
!./*.java
as well as multiple other variations of this. I came across this question that looks like it's using Regex. Is regex needed for this to work? Any ideas?
I also tried these regex patterns but I am not the best at regex.
1.Logic: ignore all files ending with the file extension pattern "java"
*
!.gitignore
!*.[^java$]
2.Logic: ignore all files ending with a "j" followed by an "a" with anything else after that.
*
!.gitignore
!*.j[^a]*
Ignoring * is a bad idea.
This will ignore every file and every directory in every part of your repository.
Especially git will not look at all at ignored directories. Therefore the exceptions you define later will have no effect at all.
There are quite longish include/exclude hacks to make something like this work, but usually the best way is to just explicitly ignore the files you want to ignore and avoid any exceptions whenever possible.
If you feel the need for some more complicated ignore rules this is usually an indicator that your repository layout needs a better structure.

Change file name with regular expression

I don't know anything about regular expressions.
How can I use a regular expressions to change a file name
I want to change a file name from 'style-dist.css' to style.css
Regex works if you can find a pattern in the strings you are trying to match/change. For example, here you have given just a single string. I am assuming you are trying to remove the '-dist' part from it? If there is some other pattern, let it be known in your question.
It can be done by
new_name = old_name.replace(/-dist/, '');
However, if you don't know regex, and have some time, I recommend getting your feet wet in it. As much as you can. Here are some introductory articles:
http://gnosis.cx/publish/programming/regular_expressions.html
http://www.javascriptkit.com/javatutors/re.shtml
And here is a more full fledged book(online):
http://regex.learncodethehardway.org/book/
If using grunt, you'll need to use the rename property in the gruntfile.
You can find more information in the grunt docs on building file objects dynamically.
You could set up your gruntfile to look something like this.
Note that you'll have to work this into your settings so that everything lines up/etc.
Note that there are no other guardrails in place here...no error checking, etc.
Note that you'll need to work out the globs for src and dest locations
Note that if you are doing this with multiple regex patterns, or your globbing patterns get really complicated, this quickly becomes a nightmare and maybe find a different way to do this.
Code:
copy: {
main: {
files: [
{
expand: true,
cwd: '<whatever your cwd is>',
src: ['<glob for your -dist.js file location>'],
dest: '<glob for a PATH..a PATH>',
rename: function(dest, src) {
// receives the dest PATH and src and then
// takes the dest path, appends the modified src using the regex
return dest + src.replace(/-dist/, '');
}
}