Perl Regex on different lines

This little example shows how to use a regex on different lines:

print reg("1n2n3n","2","-","n",2..3).$/;
print reg("1,2,3,4,5,6",".+","-",",",2..3,5..6).$/;

sub reg {
    my ($strr,$reg1,$reg2,$split,@count) = @_;
    my @elem = split($split,$strr);
        $elem[$_-1] =~ s/$reg1/$reg2/g;
    return join $split,@elem;

As Result we get this:


3 thoughts on “Perl Regex on different lines”

  1. I’ve been surfing on-line greater than 3 hours these days,
    but I by no means found any attention-grabbing article like yours.
    It’s lovely price sufficient for me. In my
    view, if all web owners and bloggers made excellent
    content as you did, the net shall be a lot more helpful
    than ever before.

  2. Hey there! This is my first visit to your blog!

    We are a collection of volunteers and starting a new project
    in a community in the same niche. Your blog provided us beneficial information to work on. You have done a extraordinary job!

  3. I do agree with all of the concepts you have introduced on your post.

    They are very convincing and will definitely work.

    Nonetheless, the posts are too short for starters.
    May you please lengthen them a little from next time?
    Thank you for the post.

Leave a Reply

Your email address will not be published.

11 − five =