MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern match exactly 0 or 1 times?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26410] Re: Pattern match exactly 0 or 1 times?
  • From: Rainer Gruber <rainer.gruber at jk.uni-linz.ac.at>
  • Date: Wed, 20 Dec 2000 00:21:34 -0500 (EST)
  • Organization: Johannes Kepler Universitaet Linz
  • References: <91f70k$548@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Gavin,

I think you are searching for something like this:

In[1]:=
f[x___ /; Length[{x}] <= 1] := something

The additional condition make sure that only if f has 0 or 1 arguments
it is evaluted to "someting".

Rainer Gruber

Gavin Scott wrote:
> 
> Is there a way to specify a pattern which will match exactly zero or
> one times?  I find myself wanting somethinglike the standard regular
> expression '?' operator, but can't see a way to do this with
> Mathematica's pattern features.  The closest I've been able to come
> is something like:
> 
>    x___ /; x=="a"
> 
> which will match zero or more copies of a specific value.  I'd like
> to match no more than one though.
> 
> Is there anything like a general Regular Expression package for
> Mathematica anywhere?  I did a quick search and didn't find anything
> like this, so I'm wondering if my desire for such a thing simply
> indicates that there's something fundamental about Mathematica
> that I don't get yet which would eliminate the need for this.
> 
> Thanks,
> 
> G.


  • Prev by Date: Re: Mathlink probs under Unix
  • Next by Date: Re: physical colors and Mathematica colors
  • Previous by thread: Re: Pattern match exactly 0 or 1 times?
  • Next by thread: Release of Analog Insydes Version 2 Beta