Dear leybniz thank you for your reply. The problem I have is not a general problem for which your solution is perfect. I want to remove tags only from a sinlge fragment of html text.
Suppose you have a long text with many annotations. What I want to do is clicking on one piece of text already annotated and give user the possibility to remove the annotation previously inserted. My question was: how can I recognize where user had clicked? How can I find from the text into the RichTextArea the annotation the user has selected?
Thank you in advance to everybody willing to help me.
I see, It seems you'd better came out with some middle-complexity algorithm finding start annotation tag first and afterwards search forward to matching closing tag.
On each text change you should (re)build tags map using regexp above, you could use Dictionary class for that purpose, something like this:
var tagsMap:Dictionary = new Dictionary();
// fill map
tagsMap[StartTagPositionIndex] = "Tag text itself";
You can trace caret move inside RichTextArea to be notified on current cursor position and if caret stands on some position which is already in your tagsMap dictionary + tag text length, and so on..
OR you could go with building full tags map as associative structure matching both begin-end tags and their details like start indexes.
ofcourse it's just an insight
Your "dictionary" solution was perfect for me, thanks a lot