regular expression

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

    regular expression

    Hi,

    being not very good at php regular expression, could anyone help me giving
    the regular expression for :
    - an e-mail address,
    - a website address (including sub-domain if possible).

    many thanks in advance,
    --
    nyso


  • Justin Koivisto

    #2
    Re: regular expression

    nyso wrote:[color=blue]
    > being not very good at php regular expression, could anyone help me giving
    > the regular expression for :
    > - an e-mail address,
    > - a website address (including sub-domain if possible).[/color]

    These are primitive, but have worked for me:
    // replace URLs that aren't in an anchor tag
    $pattern='/(http:\/\/[^\s\"\)<>]+)/i';

    // get email addresses to link
    $pattern='/([a-z][a-z0-9_.-\/]*@[^\s\"\)\?<>]+)/i';

    These are patterns that are used with the preg_* functions

    --
    Justin Koivisto - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Comment

    • Hastur Batato

      #3
      Re: regular expression

      While thinking about how cool George Washington was, nyso blurted:[color=blue]
      >
      > being not very good at php regular expression, could anyone help me giving
      > the regular expression for :
      > - an e-mail address,[/color]

      here's a cool function for checking if an email address is valid:
      (please pardon the ridiculous linewrapping)

      function is_email($email ) {

      return(preg_mat ch("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aer o|af|ag|ai|al|a m|an|ao|aq|ar|a rpa|as|at|au|aw |az|ba|bb|bd|be |bf|bg|bh|bi|bi z|bj|bm|bn|bo|b r|bs|bt|bv|bw|b y|bz|ca|cc|cd|c f|cg|ch|ci|ck|c l|cm|cn|co|com| coop|cr|cs|cu|c v|cx|cy|cz|de|d j|dk|dm|do|dz|e c|edu|ee|eg|eh| er|es|et|eu|fi| fj|fk|fm|fo|fr| ga|gb|gd|ge|gf| gh|gi|gl|gm|gn| gov|gp|gq|gr|gs |gt|gu|gw|gy|hk |hm|hn|hr|ht|hu |id|ie|il|in|in fo|int|io|iq|ir |is|it|jm|jo|jp |ke|kg|kh|ki|km |kn|kp|kr|kw|ky |kz|la|lb|lc|li |
      lk|lr|ls|lt|lu| lv|ly|ma|mc|md| mg|mh|mil|mk|ml |mm|mn|mo|mp|mq |mr|ms|mt|mu|mu seum|mv|mw|mx|m y|mz|na|name|nc |ne|net|nf|ng|n i|nl|no|np|nr|n t|nu|nz|om|org| pa|pe|pf|pg|ph| pk|pl|pm|pn|pr| pro|ps|pt|pw|py |qa|re|ro|ru|rw |sa|sb|sc|sd|se |sg|sh|si|sj|sk |sl|sm|sn|so|sr |st|su|sv|sy|sz |tc|td|tf|tg|th |tj|tk|tm|tn|to |tp|tr|tt|tv|tw |tz|ua|ug|uk|um |us|uy|uz|va|vc |ve|vg|vi|vn|vu |wf|ws|ye|yt|yu |za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $
      email));

      }

      /joe
      --
      A switch is ~bastardized!

      Comment

      • John Dunlop

        #4
        Re: regular expression

        nyso wrote:
        [color=blue]
        > being not very good at php regular expression, could anyone help me giving
        > the regular expression for :
        > - an e-mail address,[/color]

        Why? It'd be unthinkably messy.

        --
        Jock

        Comment

        • nyso

          #5
          Re: regular expression

          > > being not very good at php regular expression, could anyone help me
          giving[color=blue][color=green]
          > > the regular expression for :
          > > - an e-mail address,[/color]
          >
          > Why? It'd be unthinkably messy.
          >
          > --
          > Jock[/color]

          No, it seems easy to regex users.
          E-mail is ok but url seems more difficult.
          --
          nyso


          Comment

          • nyso

            #6
            Re: regular expression

            "Justin Koivisto" <spam@koivi.com > a écrit dans le message de news:
            Jydqb.634$Uz.16 885@news7.onvoy .net...[color=blue]
            > nyso wrote:[color=green]
            > > being not very good at php regular expression, could anyone help me[/color][/color]
            giving[color=blue][color=green]
            > > the regular expression for :
            > > - an e-mail address,
            > > - a website address (including sub-domain if possible).[/color]
            >
            > These are primitive, but have worked for me:
            > // replace URLs that aren't in an anchor tag
            > $pattern='/(http:\/\/[^\s\"\)<>]+)/i';
            >[/color]

            for the url regex, I tested it and it matches a simple "test" string as the
            minimum should be "test.somthing" .
            any idea ?
            --
            nyso


            Comment

            • John Dunlop

              #7
              Re: regular expression

              nyso wrote:
              [color=blue]
              > No, it seems easy to regex users.[/color]
              ---------^^^^^

              --
              Jock

              Comment

              • R. Rajesh Jeba Anbiah

                #8
                Re: regular expression

                "nyso" <nyso@no-spam.org> wrote in message news:<3faa1504$ 0$27035$626a54c e@news.free.fr> ...[color=blue][color=green][color=darkred]
                > > > being not very good at php regular expression, could anyone help me[/color][/color]
                > giving[color=green][color=darkred]
                > > > the regular expression for :
                > > > - an e-mail address,[/color]
                > >
                > > Why? It'd be unthinkably messy.
                > >
                > > --
                > > Jock[/color]
                >
                > No, it seems easy to regex users.
                > E-mail is ok but url seems more difficult.[/color]

                It is easy for you too. Just try http://weitz.de/regex-coach

                ---
                "Learn from yesterday, live for today, hope for tomorrow. The
                important thing is to not stop questioning."---Albert Einstein
                Email: rrjanbiah-at-Y!com

                Comment

                • nyso

                  #9
                  Re: regular expression

                  > > No, it seems easy to regex users.[color=blue][color=green]
                  > > E-mail is ok but url seems more difficult.[/color]
                  >
                  > It is easy for you too. Just try http://weitz.de/regex-coach
                  >
                  > ---
                  > "Learn from yesterday, live for today, hope for tomorrow. The
                  > important thing is to not stop questioning."---Albert Einstein
                  > Email: rrjanbiah-at-Y!com[/color]

                  thanks for the link !

                  --
                  nyso


                  Comment

                  Working...