in reply to regex replacement help

One easy way to handle your original problem (without the delim in the output) would be to use

 @out = split /~/, $string

Now, since you want the tilde as well, you could simply append ~ to the end of each substring returned by split

 @out = map {$_ .= "~"} split /~/, $string

Of course, there would be some edge cases to take care of; I didn't test this all that much. I'm a big fan of regex btw, but TIMTOWTDI

UPDATE: Didn't look closely at solution offered by wind. That's neat!
- J

Replies are listed 'Best First'.
Re^2: regex replacement help
by samarzone (Pilgrim) on Mar 30, 2011 at 07:35 UTC

    Following would be a better approach to keep the splitting pattern as well.

    @out = split /(~)/, $string
    --
    Regards
    - Samar

      Here, the splitting pattern would be a separate element

      - J

        Oh yes. I didn't notice that. Thanks.

        I should have written a positive look behind regex

        @out = split /(?<=~)/, $string;
        --
        Regards
        - Samar