From: "Rick" <rich.j...@gmail.com>
    my ($data) = $test_s =~ /(\[(.+)\]/;

I think it contains a "(" that shouldn't be there (after =~ /).

The code above assumes you want what is between the first and last
brackets in $test_s.  If the string contains more than one set of
brackets you may want to say this instead:

    my ($data) = $test_s =~ /(\[(.+?)\]/;

That ( is till there but it was surely copied by mistake, however in this case the regexp should also use a /g modifier:

my ($data) = $test_s =~ /\[(.+?)\]/g;

Understand and works fine..

I would assume either below would be also true

($data) = $data =~ /\[(.+)\]/;

and

@data = $data =~ /\[(.+)\]/;

Use .+? and use the /g modifier.

.+ would match everything from the first [ to the last ] so you will have a single element in @data. .+? would match non-greedy - everything from the first [ to the next ] so you would have more elements in @data, but only if you use /g, because otherwise @data would contain only the first element.

Octavian


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to