Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > RegExp check for nothing or pattern

Reply
Thread Tools

RegExp check for nothing or pattern

 
 
Eric
Guest
Posts: n/a
 
      12-17-2003
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



 
Reply With Quote
 
 
 
 
Carsten Aulbert
Guest
Posts: n/a
 
      12-17-2003
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.
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-17-2003
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

 
Reply With Quote
 
David Oswald
Guest
Posts: n/a
 
      12-17-2003

"Eric" <(E-Mail Removed)> 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?


 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      12-18-2003
>
> 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.


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      12-18-2003

"Eric" <(E-Mail Removed)> wrote in message
news:brs1fb$rc6$(E-Mail Removed)...
> >
> >
> > 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


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      12-18-2003
Eric <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      12-18-2003
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


 
Reply With Quote
 
Sam Holden
Guest
Posts: n/a
 
      12-18-2003
On Thu, 18 Dec 2003 19:00:09 -0000, Eric <(E-Mail Removed)> 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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      12-19-2003
Eric <(E-Mail Removed)> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re module: Nothing to repeat, but no sre_constants.error: nothing torepeat ? Devin Jeanpierre Python 2 02-14-2012 01:33 PM
regexp which matches nothing? Joao Silva Ruby 6 08-27-2009 10:20 AM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM



Advertisments