Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
grunt-regex-extract
Advanced tools
Enable the user to extract all matching results of a regular expression and save them to file
Enable the user to extract all matching results of a regular expression and save them to file
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-regex-extract --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-regex-extract');
In your project's Gruntfile, add a section named regex_extract
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
regex_extract: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: String
Default value: '(.*|\n*)'
A string value that represents the regular expression to use.
Type: String
Default value: 'ig'
A string value that determines which JavaScript RegExp modifiers to use (such as 'i' and 'g')
Type: String
Default value: '1'
A comma separated list of match points to determine what part of the regex you want to extract. Note: starts with 1
Type: boolean
Default value: 'true'
A boolean value that determines whether the path of the file is to be included in the destination file
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Hello World</title>
<script type="text/javascript" src="/js/header-js-one.js"></script>
</head>
<header>
</header>
<body>
<h1>Hello World!</h1>
<p>Foo Bar :)</p>
</body>
<footer>
<script type="text/javascript" src="/js/footer-js-one.js"></script>
<Script type="text/javascript" src="/js/footer-js-two.js"></script>
<script type="text/javascript">
var inlineFooterJsVar = "foo";
</script>
</footer>
</html>
In this example, the default options are applied but only the regex option is explicitly passed.
grunt.initConfig({
regex_extract: {
default_options: {
options: {
regex : "<script(.*|\n*)>(\s*|\n*)<\/script>"
},
files: {
'test/actual/default_options.txt': ['test/fixtures/example.html']
}
}
},
})
test/fixtures/example.html,type="text/javascript" src="/js/header-js-one.js"
test/fixtures/example.html,type="text/javascript" src="/js/footer-js-one.js"
test/fixtures/example.html,type="text/javascript" src="/js/footer-js-two.js"
In this example, all the default options are overridden
grunt.initConfig({
regex_extract: {
default_options: {
options: {
regex : "<script(.*|\n*)>(\s*|\n*)<\/(\s*|\n*)>",
modifiers: "g",
matchPoints: "1,3",
includePath : false
},
files: {
'test/actual/default_options.txt': ['test/fixtures/example.html']
}
}
},
})
type="text/javascript" src="/js/header-js-one.js",script
type="text/javascript" src="/js/footer-js-one.js",script
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Copyright (c) 2014 Miren Pau. Licensed under the MIT license.
FAQs
Enable the user to extract all matching results of a regular expression and save them to file
We found that grunt-regex-extract demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.