regular expression question

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
 
R

rowe_newsgroups

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
 
A

Andrew Morton

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
 
E

en

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...
 
P

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
 
R

rowe_newsgroups

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
 
P

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top