Reputation: 668
I'm using gulp-replace because I need to find something in my code and replace it.
I have this function:
function configure($mdIconProvider) {
$mdIconProvider
.iconSet('navigation', '/src/images/material-design-icons/navigation-icons.svg', 24)
.iconSet('action', '/src/images/material-design-icons/action-icons.svg', 24)
.iconSet('content', '/src/images/material-design-icons/content-icons.svg', 24);
}
My regex needs to find '/src/images or /images/
to replace it with the string I want because in my dev environment my path needs to be /src/images but in distribution it needs to be just /images/.
So I'll do:
gulp.task('replace-svg-path', function() {
return gulp
.src(config.appConfigJs)
.pipe(gulpif(global.isDist, replace('/src', '/images')))
.pipe(gulpif(!global.isDist, replace('/src/images || /images', '/src/images')))
.pipe(gulp.dest(config.temp));
});
Of course that the first argument of the replace function needs to be the regex.
I really don't know much about regex, can anyone help ?
Upvotes: 0
Views: 118
Reputation: 7482
To replace just /src
the regex would be/\/src/g
.
To replace /src/images
or /images
the regex would be /(\/src)?\/images/g
Upvotes: 2