in reply to Using undefined back-references?

It is one of reasons why non-capturing groups (?:...) are invented. In those cases when you do not need capturing, or get something optional in your string, just use them.

In a line where you wrote:

(\s+[^>]*)?\s+ # Optional assorted crud
write another way:
(?:\s+[^>]*)?\s+ # Optional assorted crud

Courage, the Cowardly Dog

addition: I suggest you to use a trick that fruiture later advices to you. Personally, I use that trick quite often.

Replies are listed 'Best First'.
Re: Re: Using undefined back-references?
by tommyw (Hermit) on Aug 19, 2002 at 16:22 UTC

    Won't do it, I'm afraid, 'cos I actually need to keep that crud, if it exists. Especially if somebody throws me the attributes in a different order:

    <e st="obs" num="1" st="ali">
    
    needs to group in the same way. By using ?: the entire intermediate string disappears, and I end up with
    <e st="obs,ali">
    
    Which wasn't precisely what I was after. Although it does shut the warning up :-)

    --
    Tommy
    Too stupid to live.
    Too stubborn to die.

      How about

      ((?:\s+[^>]*)?)\s+ # Optional assorted crud

      ? The capturing () is not marked with ? (or *) so it won't be undef, but the non-capturing (?:) is marked with ?, so it can fail to match: in that case the () saves an empty string, not undef.

      --
      http://fruiture.de