Would you please explain why this code does not generate what I was expecting? Why is the leading white space between the spans not excluded from the text and the trailing white space is excluded--{ leading space} instead of{leading space}? Or how do I exclude both the leading and trailing white space from the captured group?
set v {<span class='wj'> leading space </span> <span class='wj'> leading space </span> }
set vlist [regexp -all -inline -- {<span class='wj'>[[:space:]]*?(.+?)[[:space:]]*?</span>} $v]
# Result: {<span class='wj'> leading space </span>} { leading space} {<span class='wj'> leading space </span>} { leading space}
# Expectation/Goal: {<span class='wj'> leading space </span>} {leading space} {<span class='wj'> leading space </span>} {leading space}
If there is only one span it works without the ?s after [[:space:]]*. For multiple spans, if +? is used instead of *? for the leading space, it works, unless there isn't a leading space which does not match at all; and I'm not certain all instances will have a leading space. Thus, I assume it has to do with greediness with a * but I don't understand it.
Thank you.
set v {<span class='wj'> leading space </span>}
set vlist [regexp -all -inline -- {<span class='wj'>[[:space:]]*(.+?)[[:space:]]*</span>} $v]
# {<span class='wj'> leading space </span>} {leading space}