# 6.4.3 Pattern Replace

&#x20; Pattern Replace 캐릭터 필터는 **정규식(Regular Expression)**&#xC744; 이용해서 좀더 복잡한 패턴들을 치환할 수 있는 캐릭터 필터입니다. 다음은 **카멜 표기법(camelCase)**&#xC73C;로 된 단어를 대문자가 시작하는 단위 마다 공백을 삽입하여 세부 단어별로 토크나이징 될 수 있도록 **camel** 인덱스에 **camel\_analyzer** 라는 애널라이저를 생성하는 예제입니다.

{% code title="camel 인덱스에 pattern\_replace 캐릭터 필터 설정" %}

```javascript
PUT camel
{
  "settings": {
    "analysis": {
      "analyzer": {
        "camel_analyzer": {
          "char_filter": [
            "camel_filter"
          ],
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      },
      "char_filter": {
        "camel_filter": {
          "type": "pattern_replace",
          "pattern": "(?<=\\p{Lower})(?=\\p{Upper})",
          "replacement": " "
        }
      }
    }
  }
}
```

{% endcode %}

&#x20; 이제 camel 인덱스에서 **"FooBazBar"** 라는 단어를 분석 해 보면 다음과 같이 **foo**, **baz**, **bar** 세개의 단어로 분리되는 것을 확인할 수 있습니다.

{% tabs %}
{% tab title="request" %}
{% code title="camel\_analyzer 애널라이저로 문장 분석" %}

```javascript
GET camel/_analyze
{
  "analyzer": "camel_analyzer",
  "text": [
    "public void FooBazBar()"
  ]
}
```

{% endcode %}
{% endtab %}

{% tab title="response" %}
{% code title="camel\_analyzer 애널라이저로 문장 분석 결과" %}

```javascript
{
  "tokens" : [
    {
      "token" : "public",
      "start_offset" : 0,
      "end_offset" : 6,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "void",
      "start_offset" : 7,
      "end_offset" : 11,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "foo",
      "start_offset" : 12,
      "end_offset" : 14,
      "type" : "<ALPHANUM>",
      "position" : 2
    },
    {
      "token" : "baz",
      "start_offset" : 15,
      "end_offset" : 17,
      "type" : "<ALPHANUM>",
      "position" : 3
    },
    {
      "token" : "bar",
      "start_offset" : 18,
      "end_offset" : 21,
      "type" : "<ALPHANUM>",
      "position" : 4
    }
  ]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
캐릭터 필터는 토크나이저가 적용되기 이전에 해당 필드 전체 내용을 치환하는 일종의 전처리 작업입니다. 유사한 기능을 구현하여 적용하더라도 뒤에 나올 토큰필터에서 텀을 처리하는 것과는 결과에 있어 position 같은 값들의 차이가 생깁니다.
{% endhint %}


---

# 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://esbook.kimjmin.net/06-text-analysis/6.4-character-filter/6.4.3-pattern-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.
