Delphi the Regular Expression syntax (7) matches an escape character

Source: Internet
Author: User
Tags expression regular expression
// ? The meaning of the number is matched 0-1 times, if need to match? How to do
var
  reg:tperlregex;
Begin
  Reg: = Tperlregex.create (nil);
 
  Reg. Subject: = ' How are you? It's ok! ';
  Reg. RegEx   : = ' \?|! ';//Gar with \
  Reg. Replacement: = ';
  Reg. ReplaceAll;
 
  ShowMessage (Reg. Subject); Return: How are you doing?
 
  Freeandnil (reg);
End;
 
The use of escape symbols \ is sometimes possible, but sometimes problems, it is best not to use
var
  reg:tperlregex;
Begin
  Reg: = Tperlregex.create (nil);
 
  Reg. Subject: = ' How are you? It's ok! ';
  Reg. RegEx   : = ' \?| \!| \ good '; To the unnecessary "!" and "good" added \ In this case also normal
  Reg. Replacement: = ';
  Reg. ReplaceAll;
 
  ShowMessage (Reg. Subject); Return: Are you still OK
 
  Freeandnil (reg);
End;
{There would have been an option [Preextra] to prohibit the use of chaos, but the effect is not good}

Special characters in regular expressions:

Special characters Meaning in regular expressions Match the character itself
^ Matches the start of a string, or does not match the content in [] \^
$ Match end of string \$
and To mark a child expression \ (and \)
and Expressions that match "multiple characters" \[and \]
and Symbol for number of matches \{and \}
. Match all characters except line breaks \.
? Match 0 times or 1 times \?
+ Match at least 1 times \+
* Match 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.