---
title: "replaceText(_:withText:options:completionHandler:)"
framework: browserenginekit
role: symbol
role_heading: Instance Method
path: "browserenginekit/betextinput/replacetext(_:withtext:options:completionhandler:)"
---

# replaceText(_:withText:options:completionHandler:)

Replace the specified text preceding the current selection.

## Declaration

```swift
func replaceText(_ originalText: String, withText replacementText: String, options: BETextReplacementOptions = [], completionHandler: @escaping @Sendable ([UITextSelectionRect]) -> Void)
```

```swift
func replaceText(_ originalText: String, withText replacementText: String, options: BETextReplacementOptions = []) async -> [UITextSelectionRect]
```

## Discussion

Discussion Completion handler should be invoked with the rects representing the replacementText.  If the replaceText could not be completed succesfully, such as when the originalText no longer matches the current text, then the completion handler should be invoked with an empty array.
