in reply to Re^3: conditional regex
in thread conditional regex

I don't see any advantage in using /msx ...

A matter of personal taste. I find the rationale of PBP compelling with regard to 'standardizing' the behavior of the  . ^ $ metacharacters, and always using 'extended' formatting for readability.

nor \A & \z ...

Another personal preference. When generating a regex like the one used in the example, I prefer to postpone consideration of certain questions (Must the pattern be at the start of the string? May there be whitespace before it?) to the point at which the regex is actually used. Specifically WRT  \A \z I again accept the rationale of PBP for their use to anchor absolute start/end of a string (and they're almost imperative if  /m is used).

[n]or qq{} ...

I use  qq{} because I run my example code under Windoze shell and I'm trying to avoid irruptions of backwhacks. If no interpolation is involved, I'll typically use '' single-quotes.

Replies are listed 'Best First'.
Re^5: conditional regex
by BrowserUk (Patriarch) on Aug 23, 2010 at 05:13 UTC

    I can see some advantages to those in hand-written regex, but none at all for these generated regex.

    I can't imagine an application for a multi-line response to a single prompt, never mind accepting an abbreviated multi-line response.

    I like consistency in coding style, and rules-of-thumb have their place, but I think you have to apply context to decisions.

    Keeping two hands on the steering wheel is good general advice, but applied dogmatically, you'd never adjust a mirror or sun-visor; turn the radio on or off; shut the sat-nav up; scratch your ear...


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      ... not to mention that you'd spend the rest of your life in the shower if you ever really did "wash, rinse and repeat..."