regex - greedy block ()* contains wildcard -


i building grammar in antlr4, , getting warning

tl4.g4:224:12: greedy block ()* contains wildcard; non-greedy syntax ()*? may preferred

here line of code referring

block     : ( statement | functiondecl )* (return expression ';')?     ; 

what warning mean, how can correct ?

the warning telling block ()* greedy, meaning try match maximum occurrences of statement or functiondec1 which, depending on situation, might not expect.

changing ()*? makes non-greedy, suggested warning. means match minimum occurrences of statement or functiondec1.

expression examples strings:

samples:

foofoobar foobarbar foofoobarbarbar 

expression:

(foo|bar)*bar 

will give result:

foofoobar foobarbar foofoobarbarbar 

expression:

(foo|bar)*?bar 

will give result:

foofoobar foobar foofoobar 

for last one, result stop @ first bar


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -