Given an input text such where all spaces are replaced by n _ :
Hello_world_?. Hello_other_sentenc3___. World___________. I want to keep the _ between words, but I want to stick each punctuation back to the last word of a sentence without any space between last word and punctuation. I want to use the the punctuation as pivot of my regex.
I wrote the following JS-Regex:
str = str.replace(/(_| )*([:punct:])*( |_)/g, "$2$3"); This fails, since it returns :
Hello_world_?. Hello_other_sentenc3_. World_._ Why it doesn't works ? How to delete all "_" between the last word and the punctuation ? http://jsfiddle.net/9c4z5/
:punct:option in its regex implementaiton.