filter question,  

B

burntmatch2

I am needing help with this.

Only when there is more than two consecutive spaces, it truncates
replacing them with a SPACE + ANSISPACE like '  '.

So like,

EXAMPLE BEFORE: The quick brown fox.
WOULD BE AFTER: The quick brown fox.

BEFORE: The quick brown fox.
AFTER: The quick  brown fox.

BEFORE: The quick brown fox.
AFTER: The quick  brown fox.

BEFORE: The quick brown fox.
AFTER: The quick  brown fox.

Should create such results. :)
 
T

Thomas 'PointedEars' Lahn

Only when there is more than two consecutive spaces,

Given your examples, that should be "more than one".
it truncates replacing them with a SPACE + ANSISPACE like '  '.

"ANSISPACE" is nonsense. It is a no(n)-break(ing) space, as its character
entity reference indicates.

s = s.replace(/(\ )\ +/g, "$1 ");

(Escape sequences are only there for legibility; the backslashes may be
omitted.)


HTH

PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
legroups.com>, Sun, 26 Aug 2007 13:51:22, (e-mail address removed) posted:
Only when there is more than two consecutive spaces, it truncates
replacing them with a SPACE + ANSISPACE like ' &nbsp;'.

I assume that English is not your first language.

This does what you ask for : S.replace(/ {3,}/g, " $nbsp;")
This does what you want : S.replace(/ {2,}/g, " $nbsp;")

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top