[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] cut





Matthias Dorn wrote:

> Hello
>
> I am looking for a way to extract multiple occurances of a substring (in my
> case something in rectangular brackets /^<.+$>/ in such a way that the
> resultant list includes the brackets and its content.
>
> for example if i do a split at ">" somehow it gets cut of ?

    ###    The best method to put a question is
    ###        to post some test data like this:

$_ = "This is my test string. <b>And this is my bold face test string</b>";

while (/(<.*?>)/g)  {
   print $1  }

    ###   or, if you prefer a list:

print "\n\n", join "\n", @Liste = (/(<.*?>)/g);

    ###   Was it this what you ment?

    ###   .*?    makes the search non-greedy, that is: stop at the first    >
,  rather than at the last    >
    ###   ( ... )  capture the contence of the first pair of round
parenthesisses  to $1 (the second to $2 a.s.o.)
    ###   while: repeat as long as (/ ...  /g) returns true
    ###   The switch  "g" is important: "Do not return to the beginning,
    ###          but remember where you left off."

    ###   Hopefully I put a German site about regex’ in existence
    ###   (will be: http://reg-a.de (regelrechte Ausdrücke)).
    ###   You can go on asking, if you return your results to.
    ###   (wat ne Schande, daß ich hier mit einem Deutschen nicht auf deutsch
schreiben kann!!)

    ###   Netzwerkstatt
    ###   Detlef Lindenthal <detlef@lindenthal.com>


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org