Scintilla User Guide (3) - Search and Replace

黄舟
Release: 2023-03-04 21:12:02
Original
2251 people have browsed it

Scintilla provides search and replace functions, which can perform ordinary searches and regular expression searches. Scintilla's regular expressions only provide very limited basic functions.
When performing a text search, you need to set the search flag:

Search flag                                                                                                                    Description Entire radio selection

SCFIND_WORDSTART Match word start

SCFIND_REGEXP Regular expression matching

SCFIND_POSIX Regular expression matching in POSIX compatibility mode (such as Use (*) instead of /(*/))

In non-regular expression mode, when end is less than start, you can search upward and reversely; in regular expression mode, you can only Search forward downward.
In regular expressions, there are some special characters:


Character Description


. Match any character

/( Group matching start tag

/) Group matching end tag

/n n takes the value 1 – 9, indicating the result of group matching

/< Match the beginning of the word

/> Match the end of the word

/x x will be interpreted as an ordinary character, for example: /[ is interpreted as the character [

[…] Matches any character in [], such as [a-zA-Z] matches any letter

[^…] Matches not in [] Any character in

^ Matches the beginning of the line

$ Matches the end of the line

* Matches 0 or more times

+ Match 1 or more times

SCI_FINDTEXT

SCI_FINDTEXT(int flags, TextToFind *ttf)

Search text based on search flags. If found, return the starting position of the matching text, and set ttf.chrgText.cpMin and ttf.chrgText.cpMax to the starting and ending positions of the matching text, otherwise -1 is returned. SCI_FINDTEXT does not change the current selection information.

int flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
TextToFind ttf;
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = SendMessage(SCI_GETLENGTH, 0, 0);
ttf.lpstrText = "search text";
int pos = SendMessage(SCI_FINDTEXT, flags, (LPARAM)&ttf);
if (-1 != pos)
{
...
}
Copy after login

SCI_SEARCHANCHOR

SCI_SEARCHANCHOR
Set the search anchor position to the position near the beginning of the document in the current selection information and return TRUE (1). This message is usually used before calling SCI_SEARCHNEXT or SCI_SEARCHPREV. If the macro recording function is turned on, the SCI_SEARCHANCHOR message will trigger the SCN_MACRORECORD event notification.

int flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;

char *chText = "search text";


SendMessage(SCI_SEARCHANCHOR, 0, 0);
SendMessage(SCI_SEARCHNEXT, flags, (LPARAM)chText);


SCI_SEARCHNEXT

SCI_SEARCHNEXT(int searchFlags, const char *text)
Search for the specified text starting from the anchor position downwards (the end position is end of document), if found, selects the matching text and returns the starting position of the matching text, otherwise returns -1. Before using SCI_SEARCHNEXT, SCI_SEARCHANCHOR is usually called to set the anchor position. The SCI_SEARCHNEXT message does not cause the view to scroll, and the cursor is to one side near the start of the document. If the macro recording function is turned on, the SCI_SEARCHNEXT message will trigger the SCN_MACRORECORD event notification.

SCI_SEARCHPREV

SCI_SEARCHPREV(int searchFlags, const char *text)
Search for the specified text starting from the anchor position upwards (the end position is the beginning of the document), if found, select the match Text, returns the starting position of the matching text, otherwise returns -1. Before using SCI_SEARCHPREV, SCI_SEARCHANCHOR is usually called to set the anchor position. The SCI_SEARCHPREV message does not cause the view to scroll, and the cursor is to one side near the start of the document. If the macro recording function is turned on, the SCI_SEARCHPREV message will trigger the SCN_MACRORECORD event notification.

SCI_SETTARGETSTART, SCI_GETTARGETSTART

1) SCI_SETTARGETSTART(int pos)
Set the search start position and return TRUE (1). In non-regular expression mode, you can set the starting position to be greater than the ending position to perform a reverse search.
2) SCI_GETTARGETSTART

Return to the search start position.

SCI_SETTARGETEND, SCI_GETTARGETEND

1) SCI_SETTARGETEND(int pos)
Set the search end position and return TRUE (1).
2) SCI_GETTARGETEND

Returns the search end position.

SCI_TARGETFROMSELECTION

SCI_TARGETFROMSELECTION
Set the search start position and end position based on the current selection message, return TRUE (1).

SCI_SETSEARCHFLAGS, SCI_GETSEARCHFLAGS

1) SCI_SETSEARCHFLAGS(int searchFlags)
Set the search flags and return TRUE (1).
2) SCI_GETSEARCHFLAGS

Return search flags.

SCI_SEARCHINTARGET

SCI_SEARCHINTARGET(int length, const char *text)
Search for the specified text based on the information set by SCI_SETTARGETSTART, SCI_SETTARGETEND, SCI_SETSEARCHFLAGS, etc. If found, returns the starting position of the matching text, otherwise returns -1. text does not have to end with a 0 terminator, and the search text length is specified by the length parameter.

SCI_REPLACETARGET

SCI_REPLACETARGET(int length, const char *text)
Replace text based on the information set by SCI_SETTARGETSTART and SCI_SETTARGETEND. If length is -1, then text is a constant string ending with a 0 terminator, and the length of text is returned; otherwise, text does not have to end with a 0 terminator, and the length of the replacement text is specified by the parameter length, and length is returned. After replacing text, the cursor will be positioned to the side of the replacement text near the beginning of the document.
If you want to delete a piece of text, you can replace it with an empty string.

SCI_REPLACETARGETRE

SCI_REPLACETARGETRE(int length, const char *text)
Similar to SCI_REPLACETARGET, except that regular expressions are used to replace text. Text can contain character sequences such as /1 - /9. In the final generated replacement text, the matching result of the last regular expression search will be used to replace character sequences such as /1 - /9.

The above is the content of Scintilla User Guide (3) - Search and Replacement. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template