# .replace(old,new)

## Description

The `.replace()` method replaces occurrences of text in a string. It supports both literal string replacement and regular expression patterns.

## Parameters

* `old`: The text to replace. Can be either:
  * A literal string to match exactly
  * A regex pattern in the format "/pattern/flags"
* `new`: The text to replace matches with

## Usage

### Basic String Replacement

```javascript
text = "hello world"
result = text.replace("hello", "hi")
// returns "hi world"
```

### Regular Expression Replacement

```javascript
// Replace all occurrences (global flag)
text = "hello hello hello"
result = text.replace("/hello/g", "hi")
// returns "hi hi hi"

// Case insensitive match
text = "Hello HELLO hello"
result = text.replace("/hello/gi", "hi")
// returns "hi hi hi"
```

## Regex Flags

When using regex patterns, you can add flags after the closing slash:

* `g` - global (replace all matches)
* `i` - case insensitive
* `m` - multiline

## Examples

```javascript
// Basic replacement (first occurrence only)
"The cat and the cat".replace("cat", "dog")
// returns "The dog and the cat"

// Global replacement of all occurrences
"The cat and the cat".replace("/cat/g", "dog")
// returns "The dog and the dog"

// Case insensitive replacement
"Hello HELLO hello".replace("/hello/gi", "hi")
// returns "hi hi hi"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://osl.mistium.com/methods/strings/.replace.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
