Skip to content

Commit 261fd5d

Browse files
committed
Add some regex usage instructions
1 parent 54b2dd8 commit 261fd5d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ const options = {
193193
};
194194
```
195195

196+
### Custom regular expressions
197+
198+
Use the [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) constructor to create any regular expression.
199+
200+
```js
201+
const str = 'foo';
202+
const regex = new RegExp('^' + str + 'bar', 'i');
203+
const options = {
204+
from: regex,
205+
to: 'bar',
206+
};
207+
```
208+
196209
### Using callbacks for `from`
197210
You can also specify a callback that returns a string or a regular expression. The callback receives the name of the file in which the replacement is being performed, thereby allowing the user to tailor the search string. The following example uses a callback to produce a search string dependent on the filename:
198211

0 commit comments

Comments
 (0)