Re: regular express



On Thu, 28 Apr 2005 01:41:36 +0000, linda wrote:

> I have a string looks like:
>
> "hello, world! perl programming is
> great"
>
> How I can use substitute and regular express to replace multiple space
> to a single space, that is, make this string as:
>
> "hello, world! perl programming is great"
>
> Thanks in advance.

To avoid people treating this newsgroup as a script-writing service you
should always give examples of code you have tried when you post
questions.

However, as you seem to be newbie and I'm feeling generous here you go:

#!/usr/bin/perl

use strict;
use warnings;

my $line = 'hello, world! perl programming is
great';

print "$line\n";

$line =~ s/\s+/ /g;

print "$line\n";


BTW they are called regular expressions :-) Chris.
.



Relevant Pages

  • regular express
    ... I have a string looks like: ... How I can use substitute and regular express to replace multiple space to a ... single space, that is, make this string as: ...
    (perl.beginners)
  • Re: pumping lemma (third try)
    ... >> you a string not in L. ... >> contradiction and the proof that L isn't regular breaks down. ... > and answering my wannabe trials and questions. ... > there are no adjacent equal substrings. ...
    (comp.theory)
  • Re: pumping lemma (third try)
    ... some string x followed by its reverse.} ... > I will assume that L is regular and therefore the pumping lemma ... > Now I will divide the PL string w into the PL substrings x, ...
    (comp.theory)
  • Re: pumping lemma (third try)
    ... >> Duncan's comments and put my hands on a new wannabe trial using the ... >> pumping lemma on the problem below. ... I can decompose a string w belonging to L into x, ... >> being regular without that PL applies, ...
    (comp.theory)
  • Re: regex help
    ... On Sep 17, 8:58 am, Jesse Houwing ... i'm trying to see if a string ends with teh below ... Your regular expression is correct. ...
    (microsoft.public.dotnet.framework.compactframework)