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