RegExp check for nothing or pattern

Discussion in 'Perl Misc' started by Eric, Dec 17, 2003.

  1. Eric

    Eric Guest

    Hi,

    I want to write a regexp that matches either a blank value or a pattern. I'm
    checking user data for a 'telephone' field which I want to allow to be blank
    OR have at least 11 digits.

    I've tried

    if ($data =~ m/{0}|\d{11,}/) { etc etc

    But it doesn't work

    OK I know I can do it with some code, but my system reads regexps from a
    config file and I'd like to keep my system versatile.

    Cheers,

    Eric
     
    Eric, Dec 17, 2003
    #1
    1. Advertising

  2. Hi Eric,

    Eric wrote:

    > if ($data =~ m/{0}|\d{11,}/) { etc etc
    >

    Try this
    /^\s*(|\d{11,})\s*$/

    Grouping in perl is done with parentheses. I also added extra whitespaces
    which might be around your number (or your "nothing")

    If you want to use 0 as well, try
    /^\s*(|0|\d{11,})\s*$/

    And of course, read more under 'man perlre'

    HTH

    Carsten

    PS: Have you asked the owner of nowhere.com if you are alowed to use their
    domain name for email? Just asking, because it looks like you use it as a
    pseudo anti-spam address.
     
    Carsten Aulbert, Dec 17, 2003
    #2
    1. Advertising

  3. Eric wrote:
    > I want to write a regexp that matches either a blank value or a
    > pattern. I'm checking user data for a 'telephone' field which I
    > want to allow to be blank OR have at least 11 digits.
    >
    > I've tried
    >
    > if ($data =~ m/{0}|\d{11,}/) { etc etc


    /^(?:|\d{11,})$/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Dec 17, 2003
    #3
  4. Eric

    David Oswald Guest

    "Eric" <> wrote :
    >
    > I want to write a regexp that matches either a blank value or a pattern.

    I'm
    > checking user data for a 'telephone' field which I want to allow to be

    blank
    > OR have at least 11 digits.


    I posted my answer to your other post entitled: "RegExp to match pattern or
    BLANK?"

    Why did you post the same question twice with two different subject lines?
     
    David Oswald, Dec 17, 2003
    #4
  5. Eric

    Eric Guest

    >
    > I posted my answer to your other post entitled: "RegExp to match pattern

    or
    > BLANK?"
    >
    > Why did you post the same question twice with two different subject lines?
    >


    For the sole purpose of annoying you.
     
    Eric, Dec 18, 2003
    #5
  6. Eric

    Matt Garrish Guest

    "Eric" <> wrote in message
    news:brs1fb$rc6$...
    > >
    > >
    > > Why did you post the same question twice with two different subject

    lines?
    > >

    >
    > For the sole purpose of annoying you.
    >


    And in the process everyone else who reads this group. Well done!

    Matt
     
    Matt Garrish, Dec 18, 2003
    #6
  7. Eric <> wrote:
    >>
    >> I posted my answer to your other post entitled: "RegExp to match pattern

    > or
    >> BLANK?"
    >>
    >> Why did you post the same question twice with two different subject lines?
    >>

    >
    > For the sole purpose of annoying you.



    (and *thousands* of people around the world. Your selfishness is astounding)


    Goodbye troll.

    *plonk*


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 18, 2003
    #7
  8. Eric

    Eric Guest

    Jeez you guys take this so seriously don't you!

    It wasn't _really_ to annoy him, it was a simple mistake. My comment was an
    example of what's referred to as 'sarcasm'. Perhaps you've not come across
    it.

    Get a grip guys!

    Eric
     
    Eric, Dec 18, 2003
    #8
  9. Eric

    Sam Holden Guest

    On Thu, 18 Dec 2003 19:00:09 -0000, Eric <> wrote:
    > Jeez you guys take this so seriously don't you!
    >
    > It wasn't _really_ to annoy him, it was a simple mistake. My comment was an
    > example of what's referred to as 'sarcasm'. Perhaps you've not come across
    > it.
    >
    > Get a grip guys!


    A remarkably foolish thing to do. Since things like sarcasm tend not
    to work very well in usenet and email (hence the use of "smileys"), due
    to the lack of tone of voice, facial expression, etc, etc.

    This newsgroup is very high volume, and a large number of the most
    knowledgable and helpful posters use killfiles, so that they won't
    be overwhelmed by the garbage. They know that there is some
    "collateral damage", but also know that ignoring some reasonable posts
    is better than ignoring all posts (because the volume it too high).

    Welcome to the "collateral damage" group.

    --
    Sam Holden
     
    Sam Holden, Dec 18, 2003
    #9
  10. Eric <> wrote:

    > Jeez you guys take this so seriously don't you!



    There was no smiley in your followup.

    We are not mind readers.


    > Get a grip guys!



    Too late.

    Killfile entries go in, but they don't come out.

    Have a happy life.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 19, 2003
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper

    Check if is nothing

    shapper, May 30, 2007, in forum: ASP .Net
    Replies:
    12
    Views:
    582
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
    May 31, 2007
  2. Greg Hurrell
    Replies:
    4
    Views:
    167
    James Edward Gray II
    Feb 14, 2007
  3. Joao Silva
    Replies:
    16
    Views:
    381
    7stud --
    Aug 21, 2009
  4. Joao Silva

    regexp which matches nothing?

    Joao Silva, Aug 27, 2009, in forum: Ruby
    Replies:
    6
    Views:
    122
    Ralf Mueller
    Aug 27, 2009
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    494
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page