Quote:
Originally Posted by Sweetpea
I've to ask, what does the "|$" do?
|
Before explaining, I note that the expression can be simplified to
{tags:re( *(.[^\,]?)[^\,]*?(\,|$),\1\2)}
The extra parentheses were left over from an experiment.
The expression (\,|$) means (comma OR end_of_string). It causes the previous [^\,]*? to stop matching, and consumes the comma if there is one. As a side benefit, because it is parenthesized, the matched value can be used in the replacement to separate the two-letter shortened tags by that value, which is either a comma or nothing.
As long as I am in explain mode
, the explanation of the rest of the expression is:
Code:
re( *(.[^\,]?)[^\,]*?(\,|$),\1\2)
| | | | | | |_ Replace with first paren group value, followed by second
| | | | | |_Match comma or end of tags string. In parens, so remember as \2
| | | | |_ As many non-comma chars as needed
| | | |_Any character not a comma
| | |_zero or one non-comma. Still in the parens, so remembered
| |_ Any character. It is in parens, so remember it as \1
|_eat any leading blanks. They would be there because commas are followed by blanks.