# ReplaceRegExGroup 스크립트 및 차트 함수

ReplaceRegExGroup()은 입력 문자열과 지정된 복합 정규 표현식 패턴 사이의 하나 이상의 일치 항목을 바꾼 후 문자열을 반환합니다. 일치하는 텍스트를 바꾸는 텍스트는 to\_str 인수에 지정됩니다. 이 함수는 왼쪽에서 오른쪽으로 작동하지만, 음수 occurrence 값을 지정하면 함수는 오른쪽에서 왼쪽으로 읽습니다.

이 함수는 대/소문자를 구분하는 정규식 연산을 수행합니다.또는 ReplaceRegExGroupI() 변형을 사용하여 대/소문자를 구분하지 않는 정규식 작업을 수행할 수 있습니다.

ReplaceRegExGroup (text, regex, to\_str, group [, occurrence])

반환 데이터 유형: 문자열

인수

| 인수 | 설명 |
| --- | --- |
| text | to\_str의 새 텍스트로 전체 또는 일부를 바꾸려는 입력 문자열 텍스트. |
| regex | 텍스트를 바꿀 시기를 정의하는 정규 표현식.이 인수와 text 인수 간의 일치 항목이 바뀝니다. |
| to\_str | text의 기존 콘텐츠를 바꾸는 데 사용할 새 텍스트. |
| group | 합성 정규 표현식의 경우 그룹의 번호.<br><br>정규 표현식에 그룹이 하나만 포함되어 있는 경우 대신 ReplaceRegEx() 함수를 사용합니다.또는 ReplaceRegExGroup() 값을 group으로 `0`을 사용합니다.<br><br>오른쪽에서 왼쪽으로 그룹을 검색하려면 음수 group 값을 지정할 수 있습니다. |
| occurrence | 새 텍스트로 바꿀 일치 항목(입력 텍스트와 정규 표현식 간)의 번호.<br><br>이는 선택적인 인수입니다.생략하면 기본값은 0입니다.값 0을 사용하거나 인수가 생략되면 text와 regex 사이의 모든 일치 항목이 to\_str로 바뀝니다.<br><br>오른쪽에서 왼쪽으로 일치 항목을 식별하려면 occurrence에 음수 값을 지정할 수 있습니다. |

함수 예

| 예 | 결과 |
| --- | --- |
| `ReplaceRegExGroup('abc123','([a-z])([0-9]+)','x',0)` | `abx`를 반환합니다(완전한 일치 항목 바꾸기). |
| `ReplaceRegExGroup('abc123','([a-z])([0-9]+)','x',1)` | `abx123`을 반환합니다(일치하는 첫 번째 그룹만 바꿈). |
| `ReplaceRegExGroup('abc123','([a-z])([0-9]+)','x',2)` | `abcx`를 반환합니다(일치하는 두 번째 그룹만 바꿈). |
| `ReplaceRegExGroup('abc123abc123','([a-z])([0-9]+)','x',1,2)` | `abc123abx123`을 반환합니다.입력 텍스트의 첫 번째 그룹과 정규식 패턴 사이에는 두 개의 일치 항목이 있습니다.하지만 두 번째 발생만 바뀝니다. |
| `ReplaceRegExGroup('ABC123ABC123','([a-z])([0-9]+)','x',1)` | `ABC123ABC123`을 반환합니다.즉, 텍스트는 바뀌지 않습니다.이는 해당 함수가 대/소문자를 구분하고, 대/소문자를 구분하지 않는 함수 변형은 사용되지 않기 때문입니다. |
| `ReplaceRegExGroupI('ABC123ABC123','([a-z])([0-9]+)','x',1)` | `ABx123ABx123`을 반환합니다.이 예에서 텍스트 대체는 대/소문자를 구분하지 않는 함수 변형인 ReplaceRegExGroupI()이 사용되었기 때문에 발생합니다. |

## 사용 시기

ReplaceRegExGroup()을 사용하면 특히 데이터에서 복잡한 패턴을 식별해야 할 때 서식 및 규정 준수 표준에 맞게 텍스트를 수정할 수 있습니다.이 함수의 추가 group 인수를 사용하면 더 큰 텍스트 패턴의 특정 부분만 업데이트할 수 있습니다.예를 들어, URL의 특정 부분을 업데이트할 수 있습니다.

필요한 경우 이 함수를 사용하여 PII(개인 식별 정보)와 같은 중요한 정보를 가려서 응용 프로그램을 분석하는 사용자에게 표시되지 않도록 할 수도 있습니다.

## 예 1 – URL의 도메인을 업데이트하기 위한 스크립트 로드

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/ReplaceRegExGroup.htm)

#### 로드 스크립트 및 결과

개요

데이터 로드 편집기를 열고 새 섹션에 아래 로드 스크립트를 추가합니다.

로드 스크립트에는 다음이 포함됩니다.

* 특정 URL을 식별하고 업데이트하려는 입력 문자열 목록이 초기에 포함된 테이블 `URLs`.이러한 URL의 도메인을 업데이트하려고 합니다.

* 처리된 URL이 포함된 수정된 입력 텍스트가 들어 있는 필드 `ResourceURL_Updated`를 만듭니다.

* 처리할 URL을 식별하는 데 사용되는 정규 표현식을 저장하는 변수`URL_RegEx`.

요구 사항:

* 각 입력 문자열에는 두 개의 URL이 포함되어 있으며, 리소스 URL은 첫 번째 URL에 지정됩니다.첫 번째로 나열된 URL 외의 다른 URL을 업데이트하려고 하지 않습니다.

* 업데이트할 URL은 &lt;https 또는 https&gt;://&lt;domain&gt;.com/&lt;resource path&gt; 형식이어야 합니다.리소스 경로는 선택 사항이지만 이 예에서는 사용되지 않습니다.

로드 스크립트

```
Set URL_RegEx = '(https?):\/\/(([a-zA-Z0-9]+)\.([a-zA-Z0-9]*)\.??([a-zA-Z0-9]*))\/?((([a-zA-Z0-9]*)*)((\/?([a-zA-Z0-9]*)*))*)\/{0,1}([\.,;]+(?=\s))*?';

URLs:

Load
ReplaceRegExGroup(URLsList, '$(URL_RegEx)', 'replacement-server', 2,1) as ResourceURL_Updated;

Load * Inline `
URLsList
The resource is located at https://testserver.com/files. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/files/worksheet. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/files/book. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/files/form. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/datamodel. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/resourcenew. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/page. For more help, see: https://support.company.com.
The resource is located at https://testserver.com/page/overview. For more help, see: https://support.company.com.
` (delimiter is '\t');
```

결과

데이터를 로드하고 시트를 엽니다. 새 테이블을 만들고 이 필드를 차원으로 추가합니다.

* `ResourceURL_Updated`

결과 테이블

| ResourceURL\_Updated |
| --- |
| The resource is located at https://replacement-server/datamodel. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/files. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/files/book. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/files/form. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/files/worksheet. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/page. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/page/overview. For more help, see: https://support.company.com. |
| The resource is located at https://replacement-server/resourcenew. For more help, see: https://support.company.com. |

## 예 2 – URL에서 프로토콜을 업데이트하기 위한 차트 표현식

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/ReplaceRegExGroup.htm)

#### 차트 표현식 및 결과

개요

데이터 로드 편집기를 열고 새 섹션에 아래 로드 스크립트를 추가합니다.

로드 스크립트에는 다음이 포함됩니다.

* 특정 URL을 식별하고 업데이트하려는 입력 문자열 목록이 들어 있는 테이블 `URLsList`.지원 웹사이트 링크의 프로토콜을 http에서 https로 업데이트하려고 합니다.

요구 사항:

* 각 입력 문자열에는 두 개의 URL이 포함되어 있으며, 지원 웹사이트 링크가 두 번째 URL로 표시됩니다.두 번째 URL 외의 다른 URL은 업데이트하려고 하지 않습니다.

* 업데이트할 URL은 &lt;https 또는 https&gt;://&lt;domain&gt;.com/&lt;resource path&gt; 형식이어야 합니다.리소스 경로는 선택 사항이지만 이 예에서는 사용되지 않습니다.

로드 스크립트

```
URLs:

Load * Inline `
URLsList
The resource is located at https://testserver.com/files. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/files/worksheet. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/files/book. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/files/form. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/datamodel. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/resourcenew. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/page. For more help, see: http://support.company.com.
The resource is located at https://testserver.com/page/overview. For more help, see: http://support.company.com.
` (delimiter is '\t');
```

결과

데이터를 로드하고 시트를 엽니다. 새 테이블을 만들고 이 필드를 차원으로 추가합니다.

* `URLsList`

이 계산 차원을 추가합니다.

```
=ReplaceRegExGroup(URLsList, '(https?):\/\/(([a-zA-Z0-9]+)\.([a-zA-Z0-9]*)\.??([a-zA-Z0-9]*))\/?((([a-zA-Z0-9]*)*)((\/?([a-zA-Z0-9]*)*))*)\/{0,1}([\.,;]+(?=\s))*?', 'https', 1,2)
```

결과 테이블

| URLsList | =ReplaceRegExGroup(URLsList, '(https?):\/\/(([a-zA-Z0-9]+)\.([a-zA-Z0-9]\*)\.??([a-zA-Z0-9]\*))\/?((([a-zA-Z0-9]\*)\*)((\/?([a-zA-Z0-9]\*)\*))\*)\/{0,1}([\.,;]+(?=\s))\*?', 'https', 1,2) |
| --- | --- |
| The resource is located at https://testserver.com/files. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/datamodel. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/files/worksheet. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/files. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/files/book. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/files/book. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/files/form. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/files/form. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/datamodel. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/files/worksheet. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/resourcenew. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/page. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/page. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/page/overview. For more help, see: https://support.company.com. |
| The resource is located at https://testserver.com/page/overview. For more help, see: http://support.company.com. | The resource is located at https://testserver.com/resourcenew. For more help, see: https://support.company.com. |

[로드 스크립트 및 차트 표현식에서 정규 표현식 사용](https://help.qlik.com/ko-KR/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/regular-expressions-qlik-analytics.htm)