in reply to A query on greedy regexps

Greedy operators, as explained by broquaint, gobble up as much of the input text as possible that still allows the regex to match. AIUI, if the match fails, perl's regular expression engine will force one character (unicode aside) from the text matched by the .* to be "given back", to see if the rest of the expression can match. (Caveat: I've realised I need to read O'Reilly's "Mastering Regular Expressions" again, so this might well be wrong.)

Looking at the regex you've created, I can't see any advantage to making the quantifiers non-greedy - they all need to match to the end of the line anyway.

If you're looking for a robust solution, then, as I mentioned in the CB, I'd recommend installing HPUX::Ioscan and using that, or at least looking at the code to see how it does it. (Hint: It does it by looping over each line)

Summary: I think your regex is fine (although you forgot the "Class\n======\n" header at the start of your example output, so the regex won't work), although I'd still advocate using the module

cheers
davis
Is this going out live?
No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist

Replies are listed 'Best First'.
Re: Re: A query on greedy regexps
by sch (Pilgrim) on Oct 01, 2002 at 12:29 UTC

    Hi - and thanks for the pointer to HPUX::Ioscan. If I was looking to do anything heavyweight then I'd definitely use it - as it is I just want to have a list of devices I can show in different colours, which the module would do but I just thought I'd save the memory :)

    Of course, it's also (for me) another learning exercise in the black art of regex's.