Reg exp

L

Lasse Edsvik

Hello

I was wondering if you guys could help me with a pattern.

Im trying to remove every single letter word in a sentence [a-z] or [0-1]
and remove duplicate spaces in the result if any.

"a car is good" = "car is good"
"drink a beer" = "drink beer"

TIA
/Lasse
 
E

Evertjan.

Lasse Edsvik wrote on 01 feb 2005 in
microsoft.public.inetserver.asp.general:
I was wondering if you guys could help me with a pattern.

Im trying to remove every single letter word in a sentence [a-z] or [0-1]
and remove duplicate spaces in the result if any.

"a car is good" = "car is good"
"drink a beer" = "drink beer"

s = "a car is good and drink a beer"

s = s.replace(/\b.\b/g,' ') // strip the single character words
s = s.replace(/\s+/g,' ') // change all whitespaces to single space
s = s.replace(/(^\s)|(\s$)/g,'') // trim begin and end spaces

alert(s)
 
L

Lasse Edsvik

that's javascript right?


Evertjan. said:
Lasse Edsvik wrote on 01 feb 2005 in
microsoft.public.inetserver.asp.general:
I was wondering if you guys could help me with a pattern.

Im trying to remove every single letter word in a sentence [a-z] or [0-1]
and remove duplicate spaces in the result if any.

"a car is good" = "car is good"
"drink a beer" = "drink beer"

s = "a car is good and drink a beer"

s = s.replace(/\b.\b/g,' ') // strip the single character words
s = s.replace(/\s+/g,' ') // change all whitespaces to single space
s = s.replace(/(^\s)|(\s$)/g,'') // trim begin and end spaces

alert(s)
 
E

Evertjan.

Lasse Edsvik wrote on 01 feb 2005 in
microsoft.public.inetserver.asp.general:
that's javascript right?

Yes, and [but for the alert] can be used serverside in ASP.


<%
t = "a car is good and drink a beer"
response.write myStrip(t)
%>

<script language=jscript runat=server>
function myStrip(s){
s = s.replace(/\b.\b/g,' '); // strip the single character words
s = s.replace(/\s+/g,' '); // change all whitespaces to single space
s = s.replace(/(^\s)|(\s$)/g,''); // trim begin and end spaces
return s;
}
</script>
 

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

Similar Threads

reg exp 5
filter html-tags, but not all... 4
Reg Exp and sentences 8
replace words with bold words 9
reg exp help 5
Help needed with reg exp please 4
Opening for Java Developer with Idiom exp at CA 0
ChatBot 4

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top