Skip to content

Commit

Permalink
add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
le0pard committed Jul 14, 2023
1 parent 24f9883 commit 1a626fe
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ if (matchString.find()) {

#### Named Group Content

The `group()` method retrieves the content matched by a specific capturing group by name
The `group()` method retrieves the content matched by a specific name of capturing group

```js
import { RE2JS } from 're2js'
Expand All @@ -204,7 +204,27 @@ if (matchString.matches()) {

### Replacing Matches

RE2JS allows you to replace all occurrences or the first occurrence of a pattern match in a string with a specific replacement string

#### Replacing All Occurrences

The `replaceAll()` method replaces all occurrences of a pattern match in a string with the given replacement

```js
RE2JS.compile('Frog').matcher("What the Frog's Eye Tells the Frog's Brain").replaceAll('Lizard') // "What the Lizard's Eye Tells the Lizard's Brain"
RE2JS.compile('(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)').matcher('abcdefghijklmnopqrstuvwxyz123').replaceAll('$10$20') // 'jb0wo0123'
```

Note that the replacement string can include references to capturing groups from the pattern

#### Replacing the First Occurrence

The `replaceFirst()` method replaces the first occurrence of a pattern match in a string with the given replacement

```js
RE2JS.compile('Frog').matcher("What the Frog's Eye Tells the Frog's Brain").replaceFirst('Lizard') // "What the Lizard's Eye Tells the Frog's Brain"
RE2JS.compile('(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)').matcher('abcdefghijklmnopqrstuvwxyz123').replaceFirst('$10$20') // 'jb0nopqrstuvwxyz123'
```

## Performance

Expand Down

0 comments on commit 1a626fe

Please sign in to comment.