Ovid (publius_ovidius) wrote,
Ovid
publius_ovidius

  • Mood:

Bad start

You know you've having a bad start to the day day when your hungover self is doing laundry and you pull a wine glass out of the washer.

Fortunately, this was prior to the washing and it hadn't broken, but that could have been a disaster.

And to relax while fending off my hangover, I eliminated the bug in a regular expression I was working on. Believe it or not, these are much easier to write than you would think. The trick is to build smaller regexes and combine them into larger ones. Read Jeffrey Friedl's book "Mastering Regular Expressions" and you'll understand how the trivial the following really is, despite how intimidating it looks.

(?x-ism:
    ((?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b)))
    \s+
    ((?-xism:(?:=|is|[<>]=?)))
    \s+
    ((?x-ism:
    (?-xism:(?:(?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))
        \s*
    )*
)\s*(?-xism:\)))))
    \s*
    (?:
        (?-xism:[-+*/%])
        \s*
        (?-xism:(?:(?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?:(?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))|(?-xism:(?-xism:\()\s*(?x-ism:
    (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
    \s*
    (?:
        (?-xism:[-+*/%]) 
        \s*
        (?-xism:(?!\.(?![0-9]))(?:$RE{num}{real}\b|\b(?-xism:[[:upper:]][[:alnum:]_]*)\b|\b(?-xism:_)\b))
        \s*
    )*
)\s*(?-xism:\)))))
        \s*
    )*
)\s*(?-xism:\)))))
        \s*
    )*
))
    (?=[,.])
)
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 14 comments