Delphi regular expression syntax (7): matching escape characters

Source: Internet
Author: User
//? The meaning of the number is to match 0-1 times, if you need to match? How to Do var REG: tperlregex; begin REG: = tperlregex. Create (NiL); Reg. Subject: = 'Are you fine? Okay! '; Reg. RegEx: = '\? |! '; // Escape \ Reg. replacement: = '◆ '; Reg. replaceall; showmessage (Reg. subject); // return: Hello ◆ OK ◆ freeandnil (REG); end;

  // Escape characters can be used in disorder. Sometimes, problems may occur. It is best not to use VaR REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'How are you? Okay! '; Reg. RegEx: = '\? | \! | \ Haok'; // give unnecessary "! "And" good "added \ in this example, Reg is also normal. replacement: = '◆ '; Reg. replaceall; showmessage (Reg. subject); // return: You ◆ OK ◆ freeandnil (REG); end; {There is an option [preextra] To disable misuse, but the effect is not good}

Special Tables in Regular Expressions:

Special characters Meanings in Regular Expressions Matching character itself
^ Matches the start of a string or does not match the content in []. \ ^
$ Matches the end of a string \ $
(And) Mark a subexpression \ (And \)
[And] Expressions matching "multiple characters" \ [And \]
{And} Symbol of the number of matches \ {And \}
. Match All characters except line breaks \.
? Match 0 times or 1 time \?
+ Match at least once \ +
* Matches 0 times or any time \*
| Or \ |
\ Escape symbol itself \\

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.