/    Sign up×
Community /Pin to ProfileBookmark

Removing everything between : and n

I’ve got a javascript that goes like this:

[code=php]function removeSpaces(string) {
var tstring = “”;
string = ” + string;
splitstring = string.split(” “);
for(i = 0; i < splitstring.length; i++)
tstring += splitstring[i];
return tstring;
}[/code]

And to tell the truth, I didn’t write this. I just google searched for “Javascript remove spaces”…
But anyway, if I have text like this:

[quote]

1a8f1we6zs94a : ad48
af81ea8af1ge7s : a48a
….etc.

[/quote]

How can I get this, or a similar Javascript to remove the : and everything else up until the point of a line break?
So, that it turns that into

1a8f1we6zs94a
af81ea8af1ge7s

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 23.2006 — s = '1a8f1we6zs94a : ad48naf81ea8af1ge7s : a48an'

s = s.replace (/:.+?n/g, 'n')

alert (s)
Copy linkTweet thisAlerts:
@so_is_thisNov 23.2006 — Might actually want this:
s = s.replace (/s*:[^n]/g, 'n')
Copy linkTweet thisAlerts:
@mrhooNov 23.2006 — Simpler:

str=str.replace(/s*:.*/g,'');

the dot character matches everything but a line break
Copy linkTweet thisAlerts:
@so_is_thisNov 23.2006 — But, like the original suggestion (which is what I was really pointing out), you're not ensuring that any and all white space before the colon is removed.

EDIT: Ah, I see you added that part 9 hours later. ?
Copy linkTweet thisAlerts:
@AmazingAntauthorNov 24.2006 — Thanks to all of you. I got it working with mrhoo's code since it was closest to the top of my computer screen.
×

Success!

Help @AmazingAnt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...