javascript - Removing new lines except when new line preceded by double space -
i want remove new lines text, except when sentence ends in double space (i'm using javascript).
this:
this test. should turn this:
this test. but this:
this //there double space here a//but not here test. should turn this:
this test. my approach far: can replace multiple spaces followed new line single new line:
var doublespacenewline = new regexp(/(\s){2,}\n/g); test = text.replace(doublespacenewline, '\n'); but how remove newlines, without removing 1 want remain?
i prefer remove new lines except newlines preceded double or more spaces, replace double space + newline single new line.
i need regex match \s+ except when (\s){2,}\n. can't seem able combine both.
text = text.replace(" \n", '****************'); text = text.replace("\n", ' '); text = text.replace('****************', " \n"); is you're after? doesn't use regex, bit simpler of procedure.
Comments
Post a Comment