Update sed documentation regarding capture groups (#558)

* Update sed documentation regarding capture groups

* Remove unix sed example for brevity

* Regen README
This commit is contained in:
Brandon Freitag 2016-11-17 21:37:42 -08:00 committed by GitHub
parent 4a1bce8815
commit 12c103fc43
2 changed files with 18 additions and 0 deletions

View File

@ -393,6 +393,15 @@ sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
Reads an input string from `files` and performs a JavaScript `replace()` on the input
using the given search regex and replacement string or function. Returns the new string after replacement.
Note:
Like unix `sed`, ShellJS `sed` supports capture groups. Capture groups are specified
using the `$n` syntax:
```javascript
sed(/(\w+)\s(\w+)/, '$2, $1', 'file.txt');
```
### sort([options,] file [, file ...])
### sort([options,] file_array)

View File

@ -25,6 +25,15 @@ common.register('sed', _sed, {
//@
//@ Reads an input string from `files` and performs a JavaScript `replace()` on the input
//@ using the given search regex and replacement string or function. Returns the new string after replacement.
//@
//@ Note:
//@
//@ Like unix `sed`, ShellJS `sed` supports capture groups. Capture groups are specified
//@ using the `$n` syntax:
//@
//@ ```javascript
//@ sed(/(\w+)\s(\w+)/, '$2, $1', 'file.txt');
//@ ```
function _sed(options, regex, replacement, files) {
// Check if this is coming from a pipe
var pipe = common.readFromPipe();