in reply to Re: validate variable-length lines in one regex?
in thread validate variable-length lines in one regex?

Yah, this is basically what the StackOverflow fellow suggested, and it looked like something I'd really enjoy doing. Except in this situation, where I may have to do a hundred of these alternate patterns so it'd be a lot easier, albeit uglier, to keep just a list of patterns at the top of the script and toggle the one I want. They're only one line each, while the subs-pile could get huge and unreadable. We're not very concerned with best practices here since this is a one-time torture; no maintainer worries.

Anyway, it may be as you say, and impractical for other reasons after all, but it's gotten me interested in this basic question of whether the trick is possible at all. If it's true that for variable-length lines a single comparison can catch all fields but not validate, or can validate but not catch all fields, that's an interesting fundamental point.

  • Comment on Re^2: validate variable-length lines in one regex?

Replies are listed 'Best First'.
Re^3: validate variable-length lines in one regex?
by locked_user sundialsvc4 (Abbot) on Jul 07, 2015 at 00:58 UTC

    I, too, am interested.   I agree, based on this further explanation, that my original suggestion of subs could become unmanageable in the use-case that you describe.   I graciously withdraw my suggestion . . .

    The notion of building a Regex, as BrowserUK originally suggests below and as poj took and ran-with a little later on, is probably the right balance between readability and flexibility.   (All now liberally sprinkled with up-vote pixie-dust...)