Not getting multiple substitutions in Perl regex
I am trying to perform multiple substitutions on a single line of text, and it doesn't seem to be working.
QUEUE(DLR_BRKR_TIXX_IN_P开发者_JAVA技巧ROD) TYPE(QLOCAL) CURDEPTH(0) QUEUE(DLR_BRKR_TIXX_OUT_PROD) TYPE(QLOCAL) CURDEPTH(0) QUEUE(TKT_BRKR_TIXX_IN_2) TYPE(QLOCAL) CURDEPTH(0) QUEUE(TKT_BRKR_TIXX_OUT_2) TYPE(QLOCAL) CURDEPTH(0)
Regex: s/QUEUE\(([^)]*)\).*CURDEPTH\((\d+)\)/\1:\2/g
This is only matching and substituting on the first match: QUEUE(DLR_BRKR_TIXX_IN_PROD) TYPE(QLOCAL) CURDEPTH(0).
Am I missing something very obvious?
Thanks.
I think you'll find that it in fact matches from the first to the last match in one go because the .*
is greedy.
Try
s/QUEUE\(([^)]*)\).*?CURDEPTH\((\d+)\)/\1:\2/g
instead.
精彩评论