added initial caret and ending dollar sign handling