I haven't tested if the regex ever finishes, but...
Given your regexp
R.Expression:= '.+ (.+)\.(.+) GAGAL\.(.+)\. Sa.+ (.+) @';
And a string to match with over 4000 chars... => This regex will take very long (afaik).
Depending on how exactly the regex is implemented, this may go as follows (I have not verified this,
just an assumption / a guess).
=> That is, if the regex engine does not do any optimizations to the pattern.
.+ Will find every space (starting with the last) => This are over 300 spaces
=> The
entire rest of the regex, must run over 300 times (unless it matches a result)
(.+)\. Will find dots. => there are 216 dots.
=> Note that any dot that was found after the last space, will be found again after any other space.
So in the first of the above 300 loops, none may be found.
But going back for each of that 300 loops increasingly more dots are to be found, until all of them are found.
=> Assuming an equal distribution (not checked), that makes an
average of 100 dots found, in each of the above 300 loops.
The rest of the regex therefore
runs 30000 times.
(.+) GAGAL\. <space>GAGAL does not exist. But that needs to be checked 30000 times on substring of your text.
Each substrings having a length between 1 and 4000, avg 2000.
=> so 30000 * 2000 comparisons are required to check this.
=> That are 60000000 =
60 million checks.
About optimizations: Perl's regex (which is highly optimized) scans the above in no time at all. However, only if case-sensitive.
Specifying the "i" modifier, and it takes forever too.