anandvn has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Could any one please help in matching the repeated pattern in a string,

my $str = "*L*Name1*L*Name2*L**D*Place1*D*Place2*D**L*Name3*L*";
Req1: Need Name1, Name2, Name3 in a array
Req2: Need to remove *L*Name1 pattern Thanks

Replies are listed 'Best First'.
Re: Regex to find repeated patterns
by Corion (Patriarch) on Nov 18, 2010 at 09:30 UTC

    So, what code have you already written and how does it fail to work for you?

    perlretut and/or perlre might help, or maybe just split.

Re: Regex to find repeated patterns
by mjscott2702 (Pilgrim) on Nov 18, 2010 at 09:47 UTC
    Hmmm, as Corion has pointed out, you'll get much better response by showing what you have tried, and in what way it fails.

    That being said, does this code do what you are looking for?

    use strict; use warnings; my $str = "*L*Name1*L*Name2*L**D*Place1*D*Place2*D**L*Name3*L*"; my @names =$str =~ m/\*L\*(\w+)/g; print "@names\n"; $str =~ s/\*L\*$names[0]//; print "Modified string = $str\n";

    Output:

    Name1 Name2 Name3
    Modified string = *L*Name2*L**D*Place1*D*Place2*D**L*Name3*L*
Re: Regex to find repeated patterns
by JavaFan (Canon) on Nov 18, 2010 at 11:22 UTC
    Considering that "Name1", "Name2", and "Name3" are all different, how is it repeated? I do see repeated patterns here: 'L*Name', and 'D*Place' to name a few.
    Need Name1, Name2, Name3 in a array
    Uhm, @array = qw[Name1 Name2 Name3]; answers that question. But I doubt that's the answer you are looking at. Getting a useful answer (whether it's an answer you work out for yourself, or ask someone else about) starts with a clear description of the problem, not a vague, broad description, and a single, contradicting, example.
    Need to remove *L*Name1 pattern
    s/\Q*L*Name1//g;