Fixed nested/spanned node issues

Fixes a number of issues with nested/spanned nodes and simplifies the regular expressions.
``\b`` is suitable for Latin characters but it doesn't work correctly with all Unicode characters.