in reply to Should be a simple spaces/digits regex....but I'm turning grey!

' 999' or ' 9999' or '9999999' ' 9'.

Is "field" length 7 or 8 chars? What is a "field" (part of a larger string)?

but when you're checking a 16 byte filed ZZZZZZZZZZZZ9V99

Um, there is no description of what you want for that one :) one thing at a time?

whilst doing the job,is getting ludicrously large and unreadable

Instead of one regex, write twelve thirteen??

Stop writing unreadable regex :) Write beautiful regex, not ugly, so you can read :) How can I hope to use regular expressions without creating illegible and unmaintainable code?

Someone at work suggested using an sprintf in it's stead within the regex, but I must be honest and say that suggestion has left me clueless on how to do it.

Are you trying to format a string? If you are, go ahead and use sprintf, otherwise ...

write a function?

Hope this helps

  • Comment on Re: Should be a simple spaces/digits regex....but I'm turning grey!
  • Download Code

Replies are listed 'Best First'.
Re^2: Should be a simple spaces/digits regex....but I'm turning grey!
by viffer (Beadle) on Aug 05, 2014 at 07:26 UTC
    ZZZZZZZZZZZZ9V99 is just a COBOL field definition, meaning if the leading digits are 0, don't print them,
    hence a value of 9.99 with a definition of ZZ9V99 would print as 9.99,
    a definition of 999V99 would result in 009.99 being shown