Reg exp

Discussion in 'ASP General' started by Lasse Edsvik, Feb 1, 2005.

  1. Lasse Edsvik

    Lasse Edsvik Guest

    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
     
    Lasse Edsvik, Feb 1, 2005
    #1
    1. Advertising

  2. Lasse Edsvik

    Evertjan. Guest

    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)

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Feb 1, 2005
    #2
    1. Advertising

  3. Lasse Edsvik

    Lasse Edsvik Guest

    that's javascript right?


    "Evertjan." <> wrote in message
    news:Xns95F09511A4F03eejj99@194.109.133.29...
    > 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)
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
     
    Lasse Edsvik, Feb 1, 2005
    #3
  4. Lasse Edsvik

    Evertjan. Guest

    Lasse Edsvik wrote on 01 feb 2005 in
    microsoft.public.inetserver.asp.general:
    > "Evertjan." <> wrote in message


    >> 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)


    > 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>

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Feb 1, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Rowland

    Reg exp: matching relative path only.

    Andrew Rowland, Aug 2, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,159
    Andrew Rowland
    Aug 2, 2003
  2. psk

    Newbie-Reg Exp

    psk, Jan 16, 2004, in forum: Perl
    Replies:
    2
    Views:
    1,379
    Gunnar Hjalmarsson
    Jan 19, 2004
  3. PerlE

    Reg Exp Help

    PerlE, Jan 30, 2004, in forum: Perl
    Replies:
    0
    Views:
    520
    PerlE
    Jan 30, 2004
  4. Ken Chesak

    reg exp

    Ken Chesak, Aug 26, 2004, in forum: Perl
    Replies:
    0
    Views:
    645
    Ken Chesak
    Aug 26, 2004
  5. Ken Chesak

    reg exp

    Ken Chesak, Aug 30, 2004, in forum: Perl
    Replies:
    5
    Views:
    663
Loading...

Share This Page