//? 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 |
\\ |