Delphi expression Syntax (8) referencing a subexpression

Source: Internet
Author: User
Prepare: We first write a search for all English words in the expression var Reg:tperlregex;
 
  BEGIN REG: = Tperlregex.create (nil); Reg.
  Subject: = ' One Two three four five six seven eight nine '; Reg. RegEx: = ' \b[a-za-z]+\b '; This expression will be able to find all the English word reg.
  Replacement: = '; Reg.
 
  ReplaceAll; ShowMessage (Reg. Subject);
Return: Freeandnil (REG);
 
End What if we just need the first letter of each word?
This will use the subexpression//www.bianceng.cn var Reg:tperlregex;
 
  BEGIN REG: = Tperlregex.create (nil); Reg.
  Subject: = ' One Two three four five six seven eight nine '; Reg. RegEx: = ' \b ([a-za-z]) [a-za-z]*\b '; Note that there are child expressions in the expression, Reg in (). Replacement: = ' \1 '; \1 references the first subexpression, Reg.
 
  ReplaceAll; ShowMessage (Reg. Subject);
Back: O t f F S e N T freeandnil (reg);
 
End
You can have more than one subexpression var reg:tperlregex in an expression;
 
  BEGIN REG: = Tperlregex.create (nil); Reg.
  Subject: = ' One two three ten '; Reg.
  RegEx: = ' (t) (\w+) '; Reg. Replacement: = ' [\1-\2:\0] '; \1\2 the corresponding subexpression respectively; Refers to the entire expression Reg.
 
  ReplaceAll; ShowMessage (Reg. Subject); //Back: one [t-wo:two] [t-hree:three] [T-en:ten] Freeandnil (REG);
 
End
 When you introduce the methods of the Tperlregex class later, there are more topics about references to (subexpression).

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.