Home All Groups Group Topic Archive Search About

regular expression question

Author
1 May 2007 12:23 PM
PJ6
Is it possible for a regular expression to macth only an empty string? What
I want is exactly {0}, but that causes the parser to throw an exception -

parsing "{0}" - Quantifier {x,y} following nothing.

Duh, I want nothing. Maybe I need an expression that evaluates to "not
anything?" I can't find that either.

Paul

Author
1 May 2007 1:44 PM
rowe_newsgroups
On May 1, 8:23 am, "PJ6" <n***@nowhere.net> wrote:
> Is it possible for a regular expression to macth only an empty string? What
> I want is exactly {0}, but that causes the parser to throw an exception -
>
> parsing "{0}" - Quantifier {x,y} following nothing.
>
> Duh, I want nothing. Maybe I need an expression that evaluates to "not
> anything?" I can't find that either.
>
> Paul

Just to make sure I know what you're asking, could you provide the
string you are searching and exactly what you want returned?

For example:

    In the string "This is a sentence "{0}" that has the target phrase
in it."

    The regex pattern "(?<=\{).*(?=\})" will return just the character
0.

    The regex pattern "(?<="").*(?="")" will return {0}

If this isn't what you are looking for I need that extra info I
mentioned above.

Thanks,

Seth Rowe
Author
1 May 2007 1:59 PM
Andrew Morton
PJ6 wrote:
> Is it possible for a regular expression to macth only an empty
> string?

In what context? Why aren't
if stringVar is nothing then...
or
if Len(stringVar)=0 then...

sufficient?

> What I want is exactly {0}, but that causes the parser to
> throw an exception -
> parsing "{0}" - Quantifier {x,y} following nothing.

Surely you would want exactly 1 nothing, not zero nothings?

Andrew
Author
1 May 2007 2:09 PM
en
>> What I want is exactly {0}, but that causes the parser to
>> throw an exception -
>> parsing "{0}" - Quantifier {x,y} following nothing.
> Surely you would want exactly 1 nothing, not zero nothings?



I tend to agree.
If you want to detect empty strings (ie nothing) then regular expressions
seem like overkill.
The best method I would advise would be...
-------------------------------------------------------------
Myvar = String.Empty
-------------------------------------------------------------

This will also check for string = Nothing

--
Rory
Author
2 May 2007 3:43 PM
PJ6
I'm working with a validator that takes a regular expression string. I need
it to accept a certin range of values, or a completely empty value. I use |
for the OR condition. I now believe it is difficult, if not impossible, to
create a regular expresion that _only_ matches "", the empty string.

Paul

<en> wrote in message
Show quoteHide quote
news:b0ac48a0a9de8c95a19c86ea7f0@msnews.microsoft.com...
>>> What I want is exactly {0}, but that causes the parser to
>>> throw an exception -
>>> parsing "{0}" - Quantifier {x,y} following nothing.
>> Surely you would want exactly 1 nothing, not zero nothings?
>
>
>
> I tend to agree.
> If you want to detect empty strings (ie nothing) then regular expressions
> seem like overkill.
> The best method I would advise would be...
> -------------------------------------------------------------
> Myvar =
> String.Empty -------------------------------------------------------------
>
> This will also check for string = Nothing
>
> --
> Rory
>
>
Author
2 May 2007 4:08 PM
rowe_newsgroups
Show quote Hide quote
On May 2, 11:43 am, "PJ6" <n***@nowhere.net> wrote:
> I'm working with a validator that takes a regular expression string. I need
> it to accept a certin range of values, or a completely empty value. I use |
> for the OR condition. I now believe it is difficult, if not impossible, to
> create a regular expresion that _only_ matches "", the empty string.
>
> Paul
>
> <en> wrote in message
>
> news:b0ac48a0a9de8c95a19c86ea7f0@msnews.microsoft.com...
>
> >>> What I want is exactly {0}, but that causes the parser to
> >>> throw an exception -
> >>> parsing "{0}" - Quantifier {x,y} following nothing.
> >> Surely you would want exactly 1 nothing, not zero nothings?
>
> > I tend to agree.
> > If you want to detect empty strings (ie nothing) then regular expressions
> > seem like overkill.
> > The best method I would advise would be...
> > -------------------------------------------------------------
> > Myvar =
> > String.Empty -------------------------------------------------------------
>
> > This will also check for string = Nothing
>
> > --
> > Rory

> I'm working with a validator that takes a regular expression string

Is this a Asp.Net project?

Thanks,

Seth Rowe
Author
3 May 2007 2:56 PM
PJ6
> Is this a Asp.Net project?
>
> Thanks,
>
> Seth Rowe

Ha ha ha. Yes, you got me. I discovered shortly after I posed the question
that the pattern validator isn't even called when the control to be
validated is empty, and I had forgotten to remove a RequiredFieldValidator,
which immediately solved my problem.

So the question as it stands now is purely academic.

;)

Paul
Author
3 May 2007 4:03 PM
Göran_Andersson
PJ6 wrote:
> So the question as it stands now is purely academic.

And easy to solve. Match whatever you want zero or one times. The
pattern "^(\d{4})?$" for example matches either four digits or an empty
string.

--
Göran Andersson
_____
http://www.guffa.com