3
I have a log file that is searched via regex ^WebServer:.*endOfLine
. Considering the log below this regex is generating 485 iterations (Steps):
String:
amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. S
amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. S
amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. S
WebServer: error 2312. Falha de conexão com o destino. StartLine Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. Sent Request
amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. S
amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
WebServerClosed: status 10. S
The result of the capture promoted by regex is:
WebServer: error 2312. Falha de conexão com o destino. StartLine Lorem ipsum dolor sit amet, consectetur adipiscing elit...Lorem ipsum dolor sit amet, consectetur adipiscing elit...step1 endOfLine
Considering the same final product, which approach/technique has use to generate fewer iterations and the use of .*
(Greedy Repetition)?
I’m using the: https://regex101.com
On which site/language/tool did you test? In regex101, for example, only 109 Steps: https://regex101.com/r/qEI5Lz/1/ (and the non-Greedy version gets worse, takes more than 290: https://regex101.com/r/qEI5Lz/2/) - and depending on the language/tool/engine, the amount may vary, so it’s interesting to put which one you’re using and how you’re measuring
– hkotsubo
@hkotsubo yes, there in Regex Debugger function
– Fábio Jânio
Oh yeah, it’s just Debugger it counts the steps from the start, but on the main screen I think it only counts from the line, so gave less...
– hkotsubo
Anyway, I don’t think I can make it much faster, and use the quantifier Lazy, as response below actually slows down...
– hkotsubo