ReplaceRegExGroup()은 입력 문자열과 지정된 복합 정규 표현식 패턴 사이의 하나 이상의 일치 항목을 바꾼 후 문자열을 반환합니다. 일치하는 텍스트를 바꾸는 텍스트는 to_str 인수에 지정됩니다. 이 함수는 왼쪽에서 오른쪽으로 작동하지만, 음수 occurrence 값을 지정하면 함수는 오른쪽에서 왼쪽으로 읽습니다.
이 함수는 대/소문자를 구분하는 정규식 연산을 수행합니다. 또는 ReplaceRegExGroupI() 변형을 사용하여 대/소문자를 구분하지 않는 정규식 작업을 수행할 수 있습니다.
구문:
ReplaceRegExGroup
(text, regex, to_str, group [, occurrence])
반환 데이터 유형: 문자열
인수
인수
설명
text
to_str의 새 텍스트로 전체 또는 일부를 바꾸려는 입력 문자열 텍스트.
regex
텍스트를 바꿀 시기를 정의하는 정규 표현식. 이 인수와 text 인수 간의 일치 항목이 바뀝니다.
to_str
text의 기존 콘텐츠를 바꾸는 데 사용할 새 텍스트.
group
합성 정규 표현식의 경우 그룹의 번호.
정규 표현식에 그룹이 하나만 포함되어 있는 경우 대신 ReplaceRegEx() 함수를 사용합니다. 또는 group 값을 0으로 ReplaceRegExGroup()을 사용합니다.
오른쪽에서 왼쪽으로 그룹을 검색하려면 음수 group 값을 지정할 수 있습니다.
occurrence
새 텍스트로 바꿀 일치 항목(입력 텍스트와 정규 표현식 간)의 번호.
이는 선택적인 인수입니다. 생략하면 기본값은 0입니다. 값 0을 사용하거나 인수가 생략되면 text와 regex 사이의 모든 일치 항목이 to_str로 바뀝니다.
오른쪽에서 왼쪽으로 일치 항목을 식별하려면 occurrence에 음수 값을 지정할 수 있습니다.
ABx123ABx123을 반환합니다. 이 예에서 텍스트 대체는 대/소문자를 구분하지 않는 함수 변형인 ReplaceRegExGroupI()이 사용되었기 때문에 발생합니다.
사용 시기
ReplaceRegExGroup()을 사용하면 특히 데이터에서 복잡한 패턴을 식별해야 할 때 서식 및 규정 준수 표준에 맞게 텍스트를 수정할 수 있습니다. 이 함수의 추가 group 인수를 사용하면 더 큰 텍스트 패턴의 특정 부분만 업데이트할 수 있습니다. 예를 들어, URL의 특정 부분을 업데이트할 수 있습니다.
필요한 경우 이 함수를 사용하여 PII(개인 식별 정보)와 같은 중요한 정보를 가려서 앱을 분석하는 사용자에게 표시되지 않도록 할 수도 있습니다.
예 1 – URL의 도메인을 업데이트하기 위한 스크립트 로드
개요
데이터 로드 편집기를 열고 아래의 로드 스크립트를 새 탭에 추가합니다.
로드 스크립트에는 다음이 포함됩니다.
특정 URL을 식별하고 업데이트하려는 입력 문자열 목록이 초기에 포함된 테이블 URLs. 이러한 URL의 도메인을 업데이트하려고 합니다.
처리된 URL이 포함된 수정된 입력 텍스트가 들어 있는 필드 ResourceURL_Updated를 만듭니다.
처리할 URL을 식별하는 데 사용되는 정규 표현식을 저장하는 변수URL_RegEx.
요구 사항:
각 입력 문자열에는 두 개의 URL이 포함되어 있으며, 리소스 URL은 첫 번째 URL에 지정됩니다. 첫 번째로 나열된 URL 외의 다른 URL을 업데이트하려고 하지 않습니다.
업데이트할 URL은 <https 또는 https>://<도메인>.com/<리소스 경로> 형식이어야 합니다. 리소스 경로는 선택 사항이지만 이 예에서는 사용되지 않습니다.
로드 스크립트
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에서 프로토콜을 업데이트하기 위한 차트 표현식
개요
데이터 로드 편집기를 열고 아래의 로드 스크립트를 새 탭에 추가합니다.
로드 스크립트에는 다음이 포함됩니다.
특정 URL을 식별하고 업데이트하려는 입력 문자열 목록이 들어 있는 테이블 URLsList. 지원 웹사이트 링크의 프로토콜을 http에서 https로 업데이트하려고 합니다.
요구 사항:
각 입력 문자열에는 두 개의 URL이 포함되어 있으며, 지원 웹사이트 링크가 두 번째 URL로 표시됩니다. 두 번째 URL 외의 다른 URL은 업데이트하려고 하지 않습니다.
업데이트할 URL은 <https 또는 https>://<도메인>.com/<리소스 경로> 형식이어야 합니다. 리소스 경로는 선택 사항이지만 이 예에서는 사용되지 않습니다.
로드 스크립트
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');