Elisp programming 11: Regular Expression 1

Source: Internet
Author: User

Interactive Writing of Regular Expressions


For example, the buffer contains a string.


ABCD 3


Run the following command:


M-X: Re-Builder


A small buffer is displayed. Enter the regular expression D in double quotation marks. The buffer on the string is immediately highlighted with the D character. If the input is 3, the buffer is highlighted with three characters.



Special characters


Reference: http://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Special.html#Regexp-Special


'.' Represents any character (except the line break), so "a. c" can match ABC in ABCD 3.


'*' Indicates that the previous character (string) can be repeated> = 0


For example, "E *" can also match ABCD 3 in re-builder, which may lead to confusion and is generally not used in this way.


In addition, if multiple characters are followed by *, as long as one character can be matched, this is a thing that does not know where it is used.


We recommend that you try not to use this.


If * is used at the beginning, it can only represent normal characters. The same situation applies to + and ?, In a word, special characters can only be used as common characters if they are not possible.


'+' Indicates that the previous character (string) must appear at least once.


For example, "BC + D" matches the above string ABCD 3


'? 'Indicates that the previous character (string) appears once or 0 times


'^' Matches the start of a string


'&' Matches the end of a string


[...] Can contain several characters, as long as it matches one of them.


For example, the string ABCD 3 AB


Use the regular expression "[BC]" to match three values: B c and the last B.


[^...] Indicates that it cannot contain any character in [].


\ Indicates that the special character following it is only a common character.


Note: To match the \ character in a string, four \ characters are required, for example, ABCD 3 AB \ EF.


Regular Expression :"\\\\"


First, because the \ in the double quotation marks is not displayed in the elisp string writing method, to display it, it must be two \


Then, in the regular expression syntax, \ is a special character, \ can represent \,


Therefore, "\\\\" is a logical regular expression "\\", so it matches the character \


'*? ''+? ''?? 'And' * '+ ''? 'Similar functions, only non-Greedy matching, only matching the most appropriate one.





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.