Consider the string \"AB 1 BA 2 AB 3 BA\". How can I match the content between \"AB\" and \"BA\" in a non-greedy fashion (in awk)? >
For general expressions, I'm using this as a non-greedy match:
function smatch(s, r) {
if (match(s, r)) {
m = RSTART
do {
n = RLENGTH
} while (match(substr(s, m, n - 1), r))
RSTART = m
RLENGTH = n
return RSTART
} else return 0
}
smatch behaves like match, returning:
the position in
swhere the regular expressionroccurs, or 0 if it does not. The variablesRSTARTandRLENGTHare set to the position and length of the matched string.