Scintilla User Guide (3)-Search and replace

Source: Internet
Author: User
Scintilla provides search and replace functionality, which can be used for general lookups and regular expression lookups. The regular expression of Scintilla provides only a limited number of basic functions.
When you are searching for text, you need to set the search flag:

Search Flag Description

Scfind_matchcase Match Case

Scfind_wholeword matches the entire single selection

Scfind_wordstart Match Word start

Scfind_regexp Regular expression matching

Scfind_posix a regular expression match for POSIX-compliant mode (e.g. using (*) instead of/(/))

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

Character description

. Match any one character

/(group match start tag

/) group match end tag

/n value 1–9, indicating the result of a grouping match

/< Match Word start

/> Match Word End

The/x is interpreted as a normal character, for example:/[is interpreted as a character [

[...] Match any of the characters in [], such as [a-za-z] matches any letter

[^ ...] Match any character that is not in []

^ Match Line start

$ Match Line End

* Match 0 or more times

+ match 1 or more times

Sci_findtext

Sci_findtext (int flags, Texttofind *ttf)
Search for text based on the search flags flags. If found, returns the start position of the matched text and sets Ttf.chrgText.cpMin and Ttf.chrgText.cpMax to the start and end positions of the matched text, otherwise returns-1. 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) {...}

Sci_searchanchor

Sci_searchanchor
Sets the search anchor location to the current selection information near the beginning of the document, returning True (1). This message is usually used before calling Sci_searchnext or Sci_searchprev. If the macro logging feature 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)
Searches the specified text from the anchor position (ending at the end of the document) and, if found, selects the matched text, returns the start position of the matched text, or 1. The Sci_searchanchor setting anchor location is typically called before Sci_searchnext is used. Sci_searchnext messages do not cause the view to scroll, and the cursor is near the beginning of the document. If the macro logging feature is turned on, the SCI_SEARCHNEXT message will trigger the Scn_macrorecord event notification.

Sci_searchprev

Sci_searchprev (int searchFlags, const char *text)
Searches for the specified text from the anchor position upward (the end position is the beginning of the document), if found, selects the matched text, returns the starting position of the matched text, or returns-1. The Sci_searchanchor setting anchor location is typically called before Sci_searchprev is used. Sci_searchprev messages do not cause the view to scroll, and the cursor is near the beginning of the document. If the macro logging feature is turned on, the Sci_searchprev message will trigger the Scn_macrorecord event notification.

Sci_settargetstart, Sci_gettargetstart

1) sci_settargetstart (int pos)
Sets the search start position, which returns True (1). In non-regular expression mode, you can set the start position to be greater than the end position and reverse search.
2) Sci_gettargetstart
Returns the search start location.

Sci_settargetend, Sci_gettargetend

1) sci_settargetend (int pos)
Sets the search end position, which returns True (1).
2) Sci_gettargetend
Returns the search end location.

Sci_targetfromselection

Sci_targetfromselection
Returns True (1) based on the current selection message, setting the start and end position of the search.

Sci_setsearchflags, Sci_getsearchflags

1) sci_setsearchflags (int searchFlags)
Sets the search flag, which returns True (1).
2) Sci_getsearchflags
Returns the search flag.

Sci_searchintarget

Sci_searchintarget (int length, const char *text)
Searches for the specified text based on information set by Sci_settargetstart, Sci_settargetend, Sci_setsearchflags, and so on. If found, returns the starting position of the matched text, otherwise returns-1. Text does not have to end with 0 Terminator, and its search text length is specified by parameter length.

Sci_replacetarget

Sci_replacetarget (int length, const char *text)
Replaces the text according to the information set by Sci_settargetstart, Sci_settargetend. If length is-1, the text is a constant string ending with 0 terminator, which returns the length of text, otherwise, text does not have to end with 0 Terminator, the replacement text length is specified by the parameter length, and length is returned. After replacing the text, the cursor will be positioned near the beginning of the document with the replacement text.
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, the difference is that you replace text with regular expressions. In text, you can include a sequence of characters such as/1-/9, and the last occurrence of the replacement text will use the last regular expression to search for a matching result, substituting/1-/9 for a sequence of characters.

The above is the Scintilla User Guide (3)-Search and replace the content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.