Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Aug 3, 2023
1 parent 43d0624 commit 3c97494
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,6 @@ RE2JS.compile('(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)')
.replaceFirst('$10$20') // 'jb0nopqrstuvwxyz123'
```

#### Replacing with callback function

The `replaceAllFunc()` method provides a way to replace substrings in a given input string that match a compiled regular expression pattern. It offers more flexibility than a simple replacement string as it accepts a callback function to determine the replacement based on the matched substring.

```js
import { RE2JS } from 're2js'

RE2JS.compile('[a-c]')
.replaceAllFunc('defabcdef', (s) => `x${s}y`) // replace all, result: 'defxayxbyxcydef'
RE2JS.compile('[a-c]')
.replaceAllFunc('defabcdef', (s) => `x${s}y`, 1) // replace first, result: 'defxaybcdef'
```

The 3-rd argument can be used to control the number of replacements made. If it is not provided or is equal to the length of the input string, all matches in the input string will be replaced.

Ensure that the replace function (second argument) does not have any unintended side effects, as it may be called multiple times based on the number of matches and the provided limit.

### Escaping Special Characters

The `quote()` method returns a literal pattern string for the specified string. This can be useful if you want to search for a literal string pattern that may contain special characters
Expand Down

0 comments on commit 3c97494

Please sign in to comment.