What I did was fixing Ezra's given solution, I did not take the actual suggestion in account, and maybe that was a mistake from my side. Sorry for that.
Well, in that case the regular expression becomes more complicated:
code:
stringObj.replace(/\w\?(\s|$)/, "..?$1");
This example will replace all "?" with "..?" when they are preceded by an alphanumeric character (a-z, A-Z and 0-9) and followed by a white space character (new line, tab, space,...) OR the end of the string. Therefore, it's somewhat limited because it won't parse something like "Hello!?", but if you really need that too this can be fixed by using:
code:
stringObj.replace(/\w([!\?]+)(\s|$)/, "..$1$2");
but then, it'll also change "Hello!" into "Hello..!" and maybe you don't want that. To avoid that from happening, you'll need to go even further, but I'm not in the mood to do that now.