Add getOpeningIndex method and handle strings without opening or closing tags