Loading ...
Sorry, an error occurred while loading the content.

Use s/// to remove non-words BUT keep whitespace?

Expand Messages
  • hooyar66
    Is there a better way of doing this? $string =~ s/ W/_/g; $string =~ s/_/ /g; I want to remove all non-std characters EXCEPT for whitespace. With the two
    Message 1 of 6 , Sep 1, 2006
    • 0 Attachment
      Is there a better way of doing this?

      $string =~ s/\W/_/g;
      $string =~ s/_/ /g;

      I want to remove all non-std characters EXCEPT for whitespace. With
      the two statement method above it's slow and I am having to change
      whitespace to "_" and then back again.

      Thanks
      NJH
    • Paul Archer
      Is there any particular reason that $string =~ s/ W/ /g won t work for you? Have you tried it? Paul ... As democracy is perfected, the office represents, more
      Message 2 of 6 , Sep 1, 2006
      • 0 Attachment
        Is there any particular reason that
        $string =~ s/\W/ /g
        won't work for you? Have you tried it?

        Paul


        1:52pm, hooyar66 wrote:

        > Is there a better way of doing this?
        >
        > $string =~ s/\W/_/g;
        > $string =~ s/_/ /g;
        >
        > I want to remove all non-std characters EXCEPT for whitespace. With
        > the two statement method above it's slow and I am having to change
        > whitespace to "_" and then back again.
        >
        > Thanks
        > NJH
        >
        >
        >
        >
        >
        > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >



        --------------------------------------------------------------------------
        "As democracy is perfected, the office represents, more and more closely,
        the inner soul of the people. We move toward a lofty ideal. On some great
        and glorious day the plain folks of the land will reach their heart's
        desire at last, and the White House will be adorned by a downright moron."
        - H. L. Mencken, in the Baltimore Sun, July 26, 1920
        --------------------------------------------------------------------------
      • Lou Hernsen
        hey look what I found does this help? http://www.cs.tut.fi/~jkorpela/perl/regexp.html s/ w+/ /g a word : a nonempty sequence of alphanumeric characters and
        Message 3 of 6 , Sep 1, 2006
        • 0 Attachment
          hey look what I found
          does this help?

          http://www.cs.tut.fi/~jkorpela/perl/regexp.html

          s/\w+/ /g

          a "word": a nonempty sequence of alphanumeric characters and low lines
          (underscores), such as foo and 12bar8 and foo_1

          Lou

          ----- Original Message -----
          From: "hooyar66" <pcbcad@...>
          To: <perl-beginner@yahoogroups.com>
          Sent: Friday, September 01, 2006 9:52 AM
          Subject: [PBML] Use s/// to remove non-words BUT keep whitespace?


          > Is there a better way of doing this?
          >
          > $string =~ s/\W/_/g;
          > $string =~ s/_/ /g;
          >
          > I want to remove all non-std characters EXCEPT for whitespace. With
          > the two statement method above it's slow and I am having to change
          > whitespace to "_" and then back again.
          >
          > Thanks
          > NJH
          >
          >
          >
          >
          >
          > Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
          > --
          > No virus found in this incoming message.
          > Checked by AVG Free Edition.
          > Version: 7.1.405 / Virus Database: 268.11.6/428 - Release Date: 8/25/06
          >
          >
        • hooyar66
          Er... yes I ve tried it. I want to first replace non-word characters with _ , which changes whitespace too. To return my intentional whitespace I then have to
          Message 4 of 6 , Sep 1, 2006
          • 0 Attachment
            Er... yes I've tried it.

            I want to first replace non-word characters with "_", which changes
            whitespace too. To return my intentional whitespace I then have to
            convert all instances of "_" back to whitespace.

            Any _help_ appreciated.


            --- In perl-beginner@yahoogroups.com, Paul Archer <tigger@...> wrote:
            >
            > Is there any particular reason that
            > $string =~ s/\W/ /g
            > won't work for you? Have you tried it?
            >
            > Paul
            >
            >
            > 1:52pm, hooyar66 wrote:
            >
            > > Is there a better way of doing this?
            > >
            > > $string =~ s/\W/_/g;
            > > $string =~ s/_/ /g;
            > >
            > > I want to remove all non-std characters EXCEPT for whitespace.
            With
            > > the two statement method above it's slow and I am having to change
            > > whitespace to "_" and then back again.
            > >
            > > Thanks
            > > NJH
            > >
            > >
            > >
            > >
            > >
            > > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/
            groups-32.html
            > > Yahoo! Groups Links
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            >
            >
            >
            > --------------------------------------------------------------------
            ------
            > "As democracy is perfected, the office represents, more and more
            closely,
            > the inner soul of the people. We move toward a lofty ideal. On some
            great
            > and glorious day the plain folks of the land will reach their
            heart's
            > desire at last, and the White House will be adorned by a downright
            moron."
            > - H. L. Mencken, in the Baltimore Sun, July 26, 1920
            > --------------------------------------------------------------------
            ------
            >
          • merlyn@stonehenge.com
            ... Lou hey look what I found Lou does this help? Lou http://www.cs.tut.fi/~jkorpela/perl/regexp.html Date of last update: 2000-10-30 And even with that
            Message 5 of 6 , Sep 1, 2006
            • 0 Attachment
              >>>>> "Lou" == Lou Hernsen <lhernsen1015@...> writes:

              Lou> hey look what I found
              Lou> does this help?

              Lou> http://www.cs.tut.fi/~jkorpela/perl/regexp.html

              "Date of last update: 2000-10-30"

              And even with that update, it looks like it leaves out a bunch of
              Perl's regex features that were available at the time. It looks
              very perl4-ish.

              Why not just use the standard "perldoc perlre" for reference,
              and "perldoc perlretut" for a tutorial?

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
            • hooyar66
              Thanks Paul/Lou Friday afternoon brain-lapse...zzzzz ... change ... groups/ ... -- ... some ... downright ... --
              Message 6 of 6 , Sep 1, 2006
              • 0 Attachment
                Thanks Paul/Lou

                Friday afternoon brain-lapse...zzzzz

                --- In perl-beginner@yahoogroups.com, "hooyar66" <pcbcad@...> wrote:
                >
                > Er... yes I've tried it.
                >
                > I want to first replace non-word characters with "_", which changes
                > whitespace too. To return my intentional whitespace I then have to
                > convert all instances of "_" back to whitespace.
                >
                > Any _help_ appreciated.
                >
                >
                > --- In perl-beginner@yahoogroups.com, Paul Archer <tigger@> wrote:
                > >
                > > Is there any particular reason that
                > > $string =~ s/\W/ /g
                > > won't work for you? Have you tried it?
                > >
                > > Paul
                > >
                > >
                > > 1:52pm, hooyar66 wrote:
                > >
                > > > Is there a better way of doing this?
                > > >
                > > > $string =~ s/\W/_/g;
                > > > $string =~ s/_/ /g;
                > > >
                > > > I want to remove all non-std characters EXCEPT for whitespace.
                > With
                > > > the two statement method above it's slow and I am having to
                change
                > > > whitespace to "_" and then back again.
                > > >
                > > > Thanks
                > > > NJH
                > > >
                > > >
                > > >
                > > >
                > > >
                > > > Unsubscribing info is here: http://help.yahoo.com/help/us/
                groups/
                > groups-32.html
                > > > Yahoo! Groups Links
                > > >
                > > >
                > > >
                > > >
                > > >
                > > >
                > > >
                > >
                > >
                > >
                > > ------------------------------------------------------------------
                --
                > ------
                > > "As democracy is perfected, the office represents, more and more
                > closely,
                > > the inner soul of the people. We move toward a lofty ideal. On
                some
                > great
                > > and glorious day the plain folks of the land will reach their
                > heart's
                > > desire at last, and the White House will be adorned by a
                downright
                > moron."
                > > - H. L. Mencken, in the Baltimore Sun, July 26, 1920
                > > ------------------------------------------------------------------
                --
                > ------
                > >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.