Synap Editor에서 정규식에 맞는 텍스트 정보를 가져 옵니다.
Parameters:
Name | Type | Description |
---|---|---|
regex | Object | 가져올 텍스트 정규식 |
Return:
Type | Attribute | Description |
---|---|---|
Array | [ { id: "paragraphId1", text: "+제1조(목적)" }, { id: "paragraphId2", text: "+제2조(정의)" }, .... ] | text가 위치한 paragraph id와 텍스트 |
Example:
var textInfoList = editor.getTextByRegex(/\+제\d+조\([가-힣\s\d\w]+\)/g); |
getTextByRegex 활용하여 북마크 삽입 예제
문단 Id 기준으로 캐럿을 이동시키는 "setCaretById" Selection API를 활용하여 캐럿을 이동시키며, "insertBookmark" 북마크 삽입 EDIT API로 정규식으로 찾아낸 text를 bookmark Id로 사용하여 북마크 삽입.
var textInfoList = editor.getTextByRegex(/\+제\d+조\([가-힣\s\d\w]+\)/g); /* return value [ { id: "paragraphId1", text: "+제1조(목적)" }, { id: "paragraphId2", text: "+제2조(정의)" }, .... ] */ textInfoList.forEach(textInfo => { editor.execCommand('setCaretById', textInfo.id); editor.execCommand('insertBookmark', textInfo.text); }); |