I need to check if a regex pattern matches with all the target string.
For example, if the pattern is '[0-9]+':
- Target string
'123'should resultTrue - Target string
'123' + sLineBreakshould resultFalse
The code should looks like the following:
uses
System.RegularExpressions;
begin
if(TRegEx.IsFullMatch('123' + sLineBreak, '[0-9]+'))
then ShowMessage('Match all')
else ShowMessage('Not match all');
end;
I've tried TRegEx.Match(...).Success and TRegEx.IsMatch without success and I'm wondering if there is an easy way for checking if a pattern matches the whole target string.
I've also tried using ^ - start of line and $ - end of line but without any success.
uses
System.RegularExpressions;
begin
if(TRegEx.IsMatch('123' + sLineBreak, '^[0-9]+$'))
then ShowMessage('Match all')
else ShowMessage('Not match all');
end;
Here you can find an online test demonstrating that if the target string ends with a new line, the regex still matches even using start/end of line.