check a text is before or after another text
added comments for each step