Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Most unusable technology award (my nomination - regular expressions)

Most unusable technology award (my nomination - regular expressions)

Scheduled Pinned Locked Moved The Lounge
csscomalgorithmshelptutorial
65 Posts 40 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nagy Vilmos

    I think you are slightly over doing it. Isn't [A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2} enough?


    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

    N Offline
    N Offline
    NormDroid
    wrote on last edited by
    #16

    Laugh, that's far too concise :)

    Software Kinetics Wear a hard hat it's under construction
    Metro RSS

    1 Reply Last reply
    0
    • T TorstenH

      mobile phones with camera inside. Apple products. Fritzbox networking stuff. But really: String parsing is a pain in the a**, no matter how it's done. I avoid that as much as possible. and therefor I'm not forced to use regex. But when I do, I struggle my way through it like you did. Coffee and chocolate helps.

      regards Torsten When I'm not working

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #17

      TorstenH. wrote:

      Apple products

      :thumbsup: Cheer from the lounge.

      Software Kinetics Wear a hard hat it's under construction
      Metro RSS

      1 Reply Last reply
      0
      • T TorstenH

        mobile phones with camera inside. Apple products. Fritzbox networking stuff. But really: String parsing is a pain in the a**, no matter how it's done. I avoid that as much as possible. and therefor I'm not forced to use regex. But when I do, I struggle my way through it like you did. Coffee and chocolate helps.

        regards Torsten When I'm not working

        S Offline
        S Offline
        Slacker007
        wrote on last edited by
        #18

        TorstenH. wrote:

        Coffee

        Nothing like a good cup of coffee to awaken the coding beast within. :)

        Just along for the ride. "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
        "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011)

        1 Reply Last reply
        0
        • A Andrew Wiles

          Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

          www.it-workplace.com
          "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

          M Offline
          M Offline
          Minion no 5
          wrote on last edited by
          #19

          There are people who massage their ego by making the biggest and most labrythine RE possible. X|

          1 Reply Last reply
          0
          • N Nagy Vilmos

            I think you are slightly over doing it. Isn't [A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2} enough?


            Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

            A Offline
            A Offline
            Andrew Wiles
            wrote on last edited by
            #20

            Nearly, but doesn't cover the case where the user has not entered the space (i.e. 'LS1 9EL' vs 'LS19EL'). We also have some other occasional but common variations such as 'LS1_9EL' that we can try to parse for. My understanding is also that whilst this expression will validate the general format of the postcode there are specific exceptions that it does not cover. Unfortunately the task is not one of validating data at point of entry but matching data that has not been properly validated in the first place (>5m records), so refering to a web service such as the BING api is ruled out for performance reasons.

            www.it-workplace.com
            "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

            N G S M 4 Replies Last reply
            0
            • S Slacker007

              Manfred R. Bihy wrote:

              If the only tool you've got is a hammer, every problem looks like a nail!

              I like that. :thumbsup:

              Just along for the ride. "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
              "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011)

              W Offline
              W Offline
              W Balboos GHB
              wrote on last edited by
              #21

              I first saw that line was used in the end-of-mag article for "Language" magazine (an early issue). The article showed how to write a program that called a function that returned the cube of the numbers 1 through 10, doing so in a large number of languages for comparison. Interestingly, the shortest version was one of the Unix shells. I believe the magazine to have gone away to wherever they go to.

              "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

              "As far as we know, our computer has never had an undetected error." - Weisert

              "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

              S 1 Reply Last reply
              0
              • M Manfred Rudolf Bihy

                If the only tool you've got is a hammer, every problem looks like a nail! ;P Regular expressions are a very powerful tool when it comes to string matching, although as you've already stated the readability does suffer when you try to tackle complex matching operations. Still I think it is far easier than constructing a dedicated parser to accomplish the task even though there are lots of tools out there that help you in doing so: ANTLR, ProGrammar, Lex & Yacc (Bison) etc. I'm not sure though if reading a grammar is going to tickle your fanncy! :-D Cheers, Manfred

                "With sufficient thrust, pigs fly just fine."

                Ross Callon, The Twelve Networking Truths, RFC1925

                A Offline
                A Offline
                Andrew Wiles
                wrote on last edited by
                #22

                C# is my hammer! RegEx is one of those tools that was bought a long time ago for a very specific job and now lurks at the back of the toolbox. It only comes out very infrequently so: 1. I have to read the manual each time I use it because I have forgotten the instructions since the last time. 2. I am unwilling to invest the amount of time required to master its use because (refer to 1) I only use it very infrequently. 3. Each time I use it I have a lingering concern that I have left a problem for the next poor soul who has to maintain the solution.

                www.it-workplace.com
                "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                K 1 Reply Last reply
                0
                • A Andrew Wiles

                  Nearly, but doesn't cover the case where the user has not entered the space (i.e. 'LS1 9EL' vs 'LS19EL'). We also have some other occasional but common variations such as 'LS1_9EL' that we can try to parse for. My understanding is also that whilst this expression will validate the general format of the postcode there are specific exceptions that it does not cover. Unfortunately the task is not one of validating data at point of entry but matching data that has not been properly validated in the first place (>5m records), so refering to a web service such as the BING api is ruled out for performance reasons.

                  www.it-workplace.com
                  "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                  N Offline
                  N Offline
                  Nagy Vilmos
                  wrote on last edited by
                  #23

                  Andrew Wiles wrote:

                  doesn't cover the case where the user has not entered the space (i.e. 'LS1 9EL' vs 'LS19EL'). We also have some other occasional but common variations such as 'LS1_9EL'

                  Okay then: [A-Z]{1,2}[0-9R][0-9A-Z]?[ _-]{0,1}[0-9][ABD-HJLNP-UW-Z]{2} That'll work for no separator, ' ', '_' or '-'. If you want to validate the content then I would look, if possible, at not using a single regex but one per style.


                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                  N 1 Reply Last reply
                  0
                  • A Andrew Wiles

                    Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                    www.it-workplace.com
                    "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                    C Offline
                    C Offline
                    Chris Maunder
                    wrote on last edited by
                    #24

                    I find the issue with regular expressions is often how they re presented. They can be formatted to be quite neat and intuitive, if one takes the time. Many don't, and unfortunately I fall into the trap too. However, they are so ridiculously useful.

                    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                    N 1 Reply Last reply
                    0
                    • N Nagy Vilmos

                      Andrew Wiles wrote:

                      doesn't cover the case where the user has not entered the space (i.e. 'LS1 9EL' vs 'LS19EL'). We also have some other occasional but common variations such as 'LS1_9EL'

                      Okay then: [A-Z]{1,2}[0-9R][0-9A-Z]?[ _-]{0,1}[0-9][ABD-HJLNP-UW-Z]{2} That'll work for no separator, ' ', '_' or '-'. If you want to validate the content then I would look, if possible, at not using a single regex but one per style.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      N Offline
                      N Offline
                      NormDroid
                      wrote on last edited by
                      #25

                      :thumbsup: Homework answered, the most cunningly disguised programming question yet.

                      Software Kinetics Wear a hard hat it's under construction
                      Metro RSS

                      A 1 Reply Last reply
                      0
                      • C Chris Maunder

                        I find the issue with regular expressions is often how they re presented. They can be formatted to be quite neat and intuitive, if one takes the time. Many don't, and unfortunately I fall into the trap too. However, they are so ridiculously useful.

                        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                        N Offline
                        N Offline
                        NormDroid
                        wrote on last edited by
                        #26

                        Chris Maunder wrote:

                        they are so ridiculously useful

                        and so elegantly terse.

                        Software Kinetics Wear a hard hat it's under construction
                        Metro RSS

                        R 1 Reply Last reply
                        0
                        • A Andrew Wiles

                          Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                          www.it-workplace.com
                          "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                          C Offline
                          C Offline
                          CPallini
                          wrote on last edited by
                          #27

                          'cause they ain't working with regular expressions... :-D

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          1 Reply Last reply
                          0
                          • N NormDroid

                            :thumbsup: Homework answered, the most cunningly disguised programming question yet.

                            Software Kinetics Wear a hard hat it's under construction
                            Metro RSS

                            A Offline
                            A Offline
                            Andrew Wiles
                            wrote on last edited by
                            #28

                            :-D But not my actual intent...........

                            www.it-workplace.com
                            "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                            1 Reply Last reply
                            0
                            • R Rhys Gravell

                              A single Regex is really not sutable for UK post code, (incode and outcode), validation as there are post codes still in use that do not conform to current rules, (GIR 0AA as above). There are 6 valid post code formats plus one invalid one that's in use, I would probably validate each valid, (or invalid an in use), format individually with its own regex as what you've got there is pretty much unreadable... Either that or comment in a reference to the post code standards, (which can be found here...[^]), and apologise profusely to anyone that comes to that monstrosity after you :-)

                              Rhys "Technological progress is like an axe in the hands of a pathological criminal" "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"

                              R Offline
                              R Offline
                              Rob Grainger
                              wrote on last edited by
                              #29

                              That would be my approach too, and I spent a long time working with the Postal Address File in the UK. To attempt to write one regex for the whole thing leads to monstrosities like the one demonstrated. That said, I too dislike R.E.'s. They seem to me to be easy and quick to write, but tough to read. Good in an editor's search box, or tool like grep, bad in code that must be viewed by other developers. I don't object to regular languages, just the form of reg ex's that has come into use over the years. There a few examples of regular languages better done, notably in the MGrammar parser technology Microsoft tech previewed a while ago (which I guess has, unfortunately, floundered in their dev labs as they seem to have gone silent).

                              C 1 Reply Last reply
                              0
                              • N NormDroid

                                Chris Maunder wrote:

                                they are so ridiculously useful

                                and so elegantly terse.

                                Software Kinetics Wear a hard hat it's under construction
                                Metro RSS

                                R Offline
                                R Offline
                                Rob Grainger
                                wrote on last edited by
                                #30

                                Norm .net wrote:

                                elegantly terse

                                isn't that an oxymoron.

                                1 Reply Last reply
                                0
                                • A Andrew Wiles

                                  Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                                  www.it-workplace.com
                                  "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                                  P Offline
                                  P Offline
                                  Pete Appleton
                                  wrote on last edited by
                                  #31

                                  Alternate nomination: XSL

                                  -- What's a signature?

                                  S 1 Reply Last reply
                                  0
                                  • A Andrew Wiles

                                    Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                                    www.it-workplace.com
                                    "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #32

                                    It's not that bad. In c# you can format and comment them, and they start becoming understandable.

                                    1 Reply Last reply
                                    0
                                    • A Andrew Wiles

                                      Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                                      www.it-workplace.com
                                      "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                                      D Offline
                                      D Offline
                                      doc_net
                                      wrote on last edited by
                                      #33

                                      I think you are being a touch harsh on regular expressions. In this case it is the complexity of the postcode system that is causing the complexity of the regular expression not the other way round. Compare it to the regular expression for US zip codes (apologies if this is not entirely correct - this was grabbed from a quick google):

                                      ^(\d{5})(-\d{4})?$

                                      The problem is that here in the UK we use a complicated postcode system that is difficult to validate via regular expressions, but that is probably easier to read by the human eye. Plus, I would add that you have managed to validate the string in a single (albeit a very long one) line. That is a plus in my book. You could also use (again from wikipedia):

                                      [A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}

                                      as a simpler more readable alternative, but which will allow some non-existent codes that do fit the normal pattern.

                                      1 Reply Last reply
                                      0
                                      • A Andrew Wiles

                                        Nearly, but doesn't cover the case where the user has not entered the space (i.e. 'LS1 9EL' vs 'LS19EL'). We also have some other occasional but common variations such as 'LS1_9EL' that we can try to parse for. My understanding is also that whilst this expression will validate the general format of the postcode there are specific exceptions that it does not cover. Unfortunately the task is not one of validating data at point of entry but matching data that has not been properly validated in the first place (>5m records), so refering to a web service such as the BING api is ruled out for performance reasons.

                                        www.it-workplace.com
                                        "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                                        G Offline
                                        G Offline
                                        greldak
                                        wrote on last edited by
                                        #34

                                        Forcing the space is trivial - every postcode ends SPACE NUMERIC ALPHA ALPHA so if there's no space just add it. The problem only comes in if you need to deal with partial entries i.e. is B11 supposed to be B1 1?? or B11 ??? If you need to properly validate as opposed to just ensuring the format is correct you will need to perform a lookup against the likes of PAF so validating at point of entry and also performing batch validation on existing data is really the best option.

                                        1 Reply Last reply
                                        0
                                        • A Andrew Wiles

                                          Every now and then I need to solve a problem for which regular expressions looks like it is the "perfect" answer. Today that happens to be validating and extracting UK postal codes from addresses. BUT Every time I try to use regular expressions I find that no-one (especially me) has a clue how to use them and that all "posted" solutions can be demonstrated as flawed and therefore dangerous to use. The sheer complexity of the expressions makes them virtually impossible to read and therefore understand. I post the wikipedia solution to demonstrate my case (GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K [ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV] |YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9] [0-9]) [0-9][ABD-HJLNP-UW-Z]{2}) Can anyone think of a less usable technology?

                                          www.it-workplace.com
                                          "If a man speaks in a forest where there is no woman to hear him, is he still wrong?"

                                          R Offline
                                          R Offline
                                          RichK67
                                          wrote on last edited by
                                          #35

                                          Maybe my RE-fu is strong today, but this seems fairly easy to follow - just a matter of breaking it down: GIR special case (permitted letter groups starting with each letter of alphabet) number (and additional following number) London variants (E, EC, etc) etc... However, I personally would have split the London codings away from the rest, as this RE permits say "YO1EC4 1XY" which is nonsense.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups