Rules
In this challenge, I'm going to redefine the definition of "quotes" a bit.
Quotation marks (AKA quotes) are any identical characters used in pairs in various writing systems to set off direct speech, a quotation, or a phrase. The pair consists of an opening quotation mark and a closing quotation mark, which is the same character(case-sensitive).
If there are quote-pairs overlapping each other,
- If a pair nesting another, both pairs are still valid.
- If a pair not nesting another, the first starting pair remains valid. The other is no longer considered as a pair.
When counting quoted characters(length of a pair of quotes),
- The quotes themselves don't count.
- Each pair's length is counted independently. Overlapping doesn't affect another.
Goal
Your goal is to print the total length of all valid quotes. This is code golf, therefore the code with the fewest bytes wins.
Examples
Legend:
<foo>: Valid quotes
^ : Cannot be paired character
Input : ABCDDCBA
`A` (6): <BCDDCB>
`B` (4): <CDDC>
`C` (2): <DD>
`D` (0): <>
Output : 12
Input : ABCDABCD
`A` (3): <BCD>
`B` (0): ^ ^
`C` (0): ^ ^
`D` (0): ^ ^
Output : 3
Input : AABBBBAAAABA
`A` (0): <> <><> ^
`B` (0): <><> ^
Output : 0
Input : ABCDE
Output : 0
Input : Print the total length of all "quoted" characters
`r` (40): <int the total length of all "quoted" cha>
`n` (14): <t the total le>
`t` (15): < > <o> <h of all "quo>
` ` (7): ^ <total> <of> ^ ^
`h` (0): ^ ^ ^
`e` (8): < total l> ^ ^
`o` (0): ^ ^ ^
`a` (0): ^ ^ ^ ^
`l` (0): ^ ^ <>
`"` (0): ^ ^
`c` (0): ^ ^
Output : 84
Input : Peter Piper picked a peck of pickled peppers
`P` (5): <eter >
`e` (9): <t> ^ <d a p> <d p> ^
`r` (0): ^ ^
` ` (3): ^ ^ <a> <of> ^
`i` (5): <per p>
`p` (3): <er > ^ ^ ^ <>
`c` (8): <ked a pe> ^
`k` (7): ^ < of pic>
`d` (0): ^ ^
Output : 40
Input : https://www.youtube.com/watch?v=dQw4w9WgXcQ
`h` (27): <ttps://www.youtube.com/watc>
`t` (0): <> ^ ^
`/` (0): <> ^
`w` (14): <><.youtube.com/> <4>
`.` (7): <youtube>
`o` (0): ^ ^
`u` (1): <t>
`c` (0): ^ ^ ^
`Q` (8): <w4w9WgXc>
Output : 57