|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
regular expression questionIs 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 On May 1, 8:23 am, "PJ6" <n***@nowhere.net> wrote: Just to make sure I know what you're asking, could you provide the> 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 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 wrote:
> Is it possible for a regular expression to macth only an empty In what context? Why aren't> string? if stringVar is nothing then... or if Len(stringVar)=0 then... sufficient? > What I want is exactly {0}, but that causes the parser to Surely you would want exactly 1 nothing, not zero nothings?> throw an exception - > parsing "{0}" - Quantifier {x,y} following nothing. Andrew >> What I want is exactly {0}, but that causes the parser to I tend to agree.>> throw an exception - >> parsing "{0}" - Quantifier {x,y} following nothing. > Surely you would want exactly 1 nothing, not zero nothings? 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. 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 > >
Show quote
Hide quote
On May 2, 11:43 am, "PJ6" <n***@nowhere.net> wrote: Is this a Asp.Net project?> 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 Thanks, Seth Rowe > Is this a Asp.Net project? Ha ha ha. Yes, you got me. I discovered shortly after I posed the question > > Thanks, > > Seth Rowe 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 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.
Help with delegate callback error
Strange Date Problem Question about sending email via Visual Basic 2005 on a ASP.NET pa Problem with: Use the following method to smooth edges of screen fonts: if ClearType is selected Row Update Not Updating Data source Drawing One Simple Little Line File.OpenWrite vs StreamWriter Can someone help me with this menu? debug mode faster than bin\exe ? Perform transaction on 2 databases on 2 different servers. |
|||||||||||||||||||||||