Regular Expression Valhalla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Holden Caulfield

    #1

    Regular Expression Valhalla

    Hello! Does anyone know a good archive for all different types of
    Regular expressions?

    I am 90% done a website and the last 10% is putting validation on over
    100 fields. They range from needing to:

    - verify valid email (I already have this reg exp)
    - verify hexadecimal number
    - verify name would be valid as a filename
    - phone number

    Etc., etc. I figure ALL of these things have been done, so why
    re-invent the wheel. But surfing the Net looking for Regular
    Expressions is leading me to a bunch of tutorial sites and rinky dink
    Javascript sites.

    Thanks!

    Holden
  • Christopher Jeris

    #2
    Re: Regular Expression Valhalla

    commanderblop@h otmail.com (Holden Caulfield) writes:[color=blue]
    > Hello! Does anyone know a good archive for all different types of
    > Regular expressions?[/color]

    There are some references at the bottom of FAQ 4.16.


    The canonical reference is "Mastering regular expressions" by
    Jeffrey E. F. Friedl. O'Reilly, 2nd edition 2002.

    --
    Chris Jeris cjeris@oinvzer. net Apply (1 6 2 4)(3 7) to domain to reply.

    Comment

    • Dr John Stockton

      #3
      Re: Regular Expression Valhalla

      JRS: In article <6d0ce83a.04012 11407.3385ae68@ posting.google. com>, seen
      in news:comp.lang. javascript, Holden Caulfield
      <commanderblop@ hotmail.com> posted at Wed, 21 Jan 2004 14:07:55 :-[color=blue]
      >Hello! Does anyone know a good archive for all different types of
      >Regular expressions?
      >
      >I am 90% done a website and the last 10% is putting validation on over
      >100 fields. They range from needing to:
      >
      >- verify valid email (I already have this reg exp)[/color]

      Task cannot be done. Some classes of invalidity can be detected. A
      good checker will check the whole of a mail header line according to
      applicable RFCs, not just look for something like fred at hitmule dot
      con.
      [color=blue]
      >- verify hexadecimal number[/color]

      Trivial, but you must remember that different systems use different
      indicators for Hex. I am familiar with three, and aware of another,
      and expect that there are more.

      [color=blue]
      >- verify name would be valid as a filename[/color]

      Who knows what may be valid as a filename? not all file systems run DOS
      / Windows / Unix.

      [color=blue]
      >- phone number[/color]

      Impracticable, except in limited milieux. Have you understood ITU
      E.123, for example?

      [color=blue]
      >Etc., etc. I figure ALL of these things have been done, so why
      >re-invent the wheel. But surfing the Net looking for Regular
      >Expressions is leading me to a bunch of tutorial sites and rinky dink
      >Javascript sites.[/color]

      There is in addition the question of how best to make use of RegExps in
      quantity without repetitive coding.

      <URL:http://www.merlyn.demo n.co.uk/js-valid.htm> refers.


      BTW, do you come from a country where International Standards are
      generally known and respected by the technical community? If not, you
      might do better to explicitly address only that limited audience, and
      leave the wider task to those in a better position to appreciate it.

      Unless you can be absolutely sure of accepting for a given field all
      forms that are valid or may become valid within the like of the code,
      you need to make the checking advisory only.


      N.B. Dates can be fully validated; but only if the input is not free-
      format. Consider 13/09/1752 - is it valid? 1700-02-29?

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      • Holden Caulfield

        #4
        Re: Regular Expression Valhalla

        Thanks, but...
        [color=blue]
        > There are some references at the bottom of FAQ 4.16.
        > http://jibbering.com/faq/[/color]

        1 of the 2 links is a 404, and the working link (to a doc I already
        have) is an introductory lesson on making my own.

        I do not want to reinvent the wheel.

        Does no one know of a good source for ready-to-go Regular
        Expressions??

        Thanks,

        H.C.

        Comment

        • Christopher Jeris

          #5
          Re: Regular Expression Valhalla

          commanderblop@h otmail.com (Holden Caulfield) writes:[color=blue]
          > Does no one know of a good source for ready-to-go Regular
          > Expressions??[/color]

          I personally wouldn't use such a source any more.

          I posted what I thought was a good expression for syntactically
          correct email addresses. It was even taken from a pretty respectable
          source (Danny Goodman's "Dynamic HTML: The Definitive Reference").
          Lasse (and some others? I don't remember) pointed out quite correctly
          that it was a long way from accepting all email addresses valid
          according to RFC 2822. I didn't read the spec. I guess Goodman
          didn't either.

          The effort you exert to "reinvent the wheel" is likely to be
          comparable to the effort you exert to try two or three dubious
          candidates from various sources, dissect them symbol-by-symbol and
          test boundary cases to verify that they meet your needs. If you've
          defined your needs precisely enough that you can do that, you know
          almost everything you need to know to write the expression yourself
          anyway.

          All that being said, I suppose that /[0-9A-Fa-f]*/ can be relied upon
          to match a string of zero or more hexadecimal digits, _if_ your
          definition of "hexadecima l digit" is "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,
          B, C, D, E, F, a, b, c, d, e, or f". Whether that definition is
          satisfactory depends on your needs. In India, for example, the
          customary decimal numerals are different and have different code
          points in Unicode; I don't know what the customary hexadecimal
          numerals are.

          The point, which I am belaboring, is that you must know _exactly_ the
          class of strings you intend to accept, and then you have more or less
          written the expression already.

          And, as other people say about once a day on this group, you cannot
          rely on client-side form validation, so you have to duplicate your
          expressions (possibly in a language with slightly different RE
          semantics) server-side.

          --
          Chris Jeris cjeris@oinvzer. net Apply (1 6 2 4)(3 7) to domain to reply.

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Regular Expression Valhalla

            Christopher Jeris <cjeris@oinvzer .net> writes:
            [color=blue]
            > All that being said, I suppose that /[0-9A-Fa-f]*/ can be relied upon
            > to match a string of zero or more hexadecimal digits,[/color]

            Actually, it matches all strings whatsoever. You forgot to anchor it as
            /^[0-9A-Fa-f]$/. Your regular expression matches a string if it contains
            a substring that is zero or more hexadecimal digits. All strings contain
            a substring of length zero.

            I have made that mistake far to often myself, and would have preferred
            if matches always had to be against the entire string. Then you could
            add .* before and after if you wanted it. But, alas, that was not the
            way they did it, probably for historical reasons.
            [color=blue]
            > The point, which I am belaboring, is that you must know _exactly_ the
            > class of strings you intend to accept, and then you have more or less
            > written the expression already.[/color]

            I concur.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • usman

              #7
              Re: Regular Expression Valhalla



              Explore, test, and learn regular expressions with our interactive tools and comprehensive library of regex patterns.



              thanks

              usman shaheen

              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Christopher Jeris

                #8
                Re: Regular Expression Valhalla

                Lasse Reichstein Nielsen <lrn@hotpop.com > writes:[color=blue]
                > Christopher Jeris <cjeris@oinvzer .net> writes:[color=green]
                > > All that being said, I suppose that /[0-9A-Fa-f]*/ can be relied upon
                > > to match a string of zero or more hexadecimal digits,[/color]
                > Actually, it matches all strings whatsoever. You forgot to anchor it as
                > /^[0-9A-Fa-f]*$/. Your regular expression matches a string if it contains
                > a substring that is zero or more hexadecimal digits. All strings contain
                > a substring of length zero.[/color]

                Well, it depends on what you mean by 'match', right?

                If what you want is a test "does the input string belong to the language
                generated by this regular expression", then of course you're right.

                If you want "give the initial segment of the input string matched by
                this expression", then the anchors aren't appropriate, correct?

                I wish I could say that I was thinking about this when I wrote my post,
                but in fact you've merely caught another of my novice mistakes posted
                to the group. Maybe I should shut up. :)

                --
                Chris Jeris cjeris@oinvzer. net Apply (1 6 2 4)(3 7) to domain to reply.

                Comment

                • Dr John Stockton

                  #9
                  Re: Regular Expression Valhalla

                  JRS: In article <ximd69bfvjl.fs f@hsph.harvard. edu>, seen in
                  news:comp.lang. javascript, Christopher Jeris <cjeris@oinvzer .net> posted
                  at Thu, 22 Jan 2004 17:49:50 :-[color=blue]
                  >
                  >And, as other people say about once a day on this group, you cannot
                  >rely on client-side form validation, so you have to duplicate your
                  >expressions (possibly in a language with slightly different RE
                  >semantics) server-side.[/color]

                  Not invariably.

                  NONE of my Web pages submit anything, and several of those not called
                  js-*.htm contain inputs which might be validated.

                  One with a university address should not be assuming that the "business-
                  and-customer" model applies everywhere.

                  In these pages, on the whole I tend to consider it sufficient if all
                  input either is valid or causes manifest nonsense output (such as a date
                  with the numeric fields all the string "NaN").

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                  <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                  <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                  <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                  Comment

                  • Holden Caulfield

                    #10
                    Re: Regular Expression Valhalla

                    Thanks Usman!

                    That´s what I am looking for, links to ready-made expressions! I can
                    sort through these and pick out the one best suited to my needs...

                    Thank you,

                    H.C.

                    Comment

                    Working...