quote:
Originally posted by markee
Why use such a complex regular expression when you can do the same by this.
code:
var nMessage = Message.replace(/teh/gi, "the");
This will do exactly the same thing as what your regular expression did except it is smaller and less confusing for those that are new to regular expressions.
You should've read his question twice:
quote:
Originally posted by TazDevil
and how can i check if it is the actual word and not part of the word
eg. teh is replaced by the but the function should not replace tehn with then
t-h combination is what i type wrong most of the times...
thanks
He wants to have "teh" replaced, but not "tehn". With your simpler expression, it'll replace
all occurrences of "teh", including "tehn". With my somewhat complexer expression, it'll only replace when:
- "teh" is at the begin of the string OR preceded by a space or newline AND
- "teh" is at the end of the string OR proceeded by a space or newline.
When it matches, it'll also re-add the captured spaces and newline characters to keep the remaining string intact.