Consider a regex
".*?\s*$"
and a line that does not end with a space.
Example
" a". The final \sone can never match a, so the iterator does the following:
\s\s\s\s\s - fails
.\s\s\s\s - fails
..\s\s\s - fails
...\s\s - fails
....\s - fails
..... - succeeds
If, however, the regular expression matches the leading space ( "^\s*.*?"), the match will succeed without any backtracking . (And if the original regular expression were matched backward (that is, starting from the last character and working backward), it will also work right away.)
Is there any way to hint / help the engine in a trailing case? Or is it just like that?
( . , . trim() , / .)