DaveOfTheDogs
DaveOfTheDogs

Reputation: 81

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_PROD) 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.

Upvotes: 2

Views: 144

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336158

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.

Upvotes: 4

Related Questions