regular expression question

  • Thread starter Thread starter PJ6
  • Start date Start date
P

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
 
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
 
PJ6 said:
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
 
What I want is exactly {0}, but that causes the parser to
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...
 
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
 
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

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...
This will also check for string = Nothing

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

Is this a Asp.Net project?

Thanks,

Seth Rowe
 
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
 
PJ6 said:
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.
 
Back
Top