getTextByRegex

Release 2.3.0 and above.

Gets text information matching a regular expression in Synap Editor.

Parameters:

NameTypeDescription
regexObjectRegular expression for the text to retrieve.

Return:

<table> <thead> <tr><th>Type</th><th>Attribute</th><th>Description</th></tr> </thead> <tbody> <tr> <td>Array</td> <td>
[
    { id: "paragraphId1", text: "+Article 1 (Purpose)" },
    { id: "paragraphId2", text: "+Article 2 (Definitions)" },
    ....
]
</td> <td>The paragraph id where the text is located and the text.</td> </tr> </tbody> </table>

Example:

var textInfoList = editor.getTextByRegex(/\+Article\s\d+\s\([A-Za-z\s\d\w]+\)/g);

Usage example

Example of inserting bookmarks using getTextByRegex

Use the setCaretById Selection API, which moves the caret based on the paragraph Id, to move the caret, and use the insertBookmark Bookmark Insert EDIT API to insert bookmarks using the text found by the regular expression as the bookmark Id.

Example:

var textInfoList = editor.getTextByRegex(/\+Article\s\d+\s\([A-Za-z\s\d\w]+\)/g);
/* return value
[
    { id: "paragraphId1", text: "+Article 1 (Purpose)" },
    { id: "paragraphId2", text: "+Article 2 (Definitions)" },
    ....
]
*/

textInfoList.forEach(textInfo => {
    editor.execCommand('setCaretById', textInfo.id);
    editor.execCommand('insertBookmark', textInfo.text);
});

The generated bookmarks can be used to create table-of-contents hyperlinks.