perl - Does the greediness of a regex matter after all need matches have been used? -
the title pretty says all.
i have regex need match names of virtual machines array.
the regex looks this:
/^(?<id> \d+)\s+(?<name> .+?)\s+\[.+\]/mx
after last capture group matched have no need left overs other using them stop match @ correct place characters in capture group correctly matched. matter how greedy left overs if not being used?
here example of string matching, before match.
432 test box åäö!"''*# [store] test box +w6xdpmo2iq-_''_+iw/test box +w6xdpmo2iq-_''_+iw.vmx slesguest vmx-04
here example if string matching, after match.
432 test box åäö!"''*#
like ask above, if need first 2 capture groups matter how greedy uncaptured part @ end is?
there no difference between \s+
, \s+?
long preceding quantifier .+?
remains lazy; match @ least 1 space , expand needed until following [
.
i first said there might difference between \[.+\]
, \[.+?\]
if more 1 pair of data items can occur on same line. former match in case. noticed you've anchored regex start of line. no, in case, doesn't matter either.
Comments
Post a Comment