in reply to finding nonword character at end of strings

Use a character class:

$f =~ s/\s(i|a|e|o|u|y|E):(\s|$)/ $1 /;

I also changed the \1 to a $1, since $1 will catch the matched value in parens.

Update: Of course iakobski and Hofmator are right, so don't look here, look further down.
I changed the errornous code.

Replies are listed 'Best First'.
Re: Re: finding nonword character at end of strings
by iakobski (Pilgrim) on Jun 26, 2001 at 14:45 UTC
    Good try, but you cannot use "end of string" in a character class. Also, the parser sees $] as a variable and cannot find the closing brace.

    Try this one:

    $f =~ s/\s(i|a|e|o|u|y|E):(\s|$)/ $1$2/;
    It also captures the space or end of string and uses that rather than a space: this may or may not be what you want.

    -- iakobski

      In your solution the $ in the character class uses its special meaning and becomes a literal '$'. You have to use a |-construct. Furthermore I would use a characterclass for the first part ... this leads to

      $f =~ s/\s([iaeouyE]):(?:\s|$)/ $1 /;

      Update: Oops, this was meant as a reply to busunsl not to iakobski ...

      Update 2: and bikeNomad discovered some left out paras ... thanks, fixed it

      -- Hofmator