473,890 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regular expression question

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
May 1 '07 #1
7 5900
On May 1, 8:23 am, "PJ6" <n...@nowhere.n etwrote:
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

May 1 '07 #2
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
May 1 '07 #3
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
May 1 '07 #4
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

<enwrote in message
news:b0******** *************** **@msnews.micro soft.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


May 2 '07 #5
On May 2, 11:43 am, "PJ6" <n...@nowhere.n etwrote:
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

<enwrote in message

news:b0******** *************** **@msnews.micro soft.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

May 2 '07 #6
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 RequiredFieldVa lidator,
which immediately solved my problem.

So the question as it stands now is purely academic.

;)

Paul
May 3 '07 #7
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
May 3 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9755
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
5
2541
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL, and then reconstruct another URL based on it. For example, I need to scan a web page looking for something like <a href="some_dir/list_20050815100225.csv">. I don't know in advance what the date/time in the file name will be. I need to take the...
10
3054
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In other words, as the regular expression (....)($) matches the "4567" in the string "1234567", how would I create a similar regular expression that only matches the "45" in the same string. The same regular expression would match "32" in the string...
18
3051
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
5
3115
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address and this method does not.... Does anyone have an explanation? Function IsValidEmail(ByVal strIn As String) As Boolean
7
371
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist - Album- i have try this syntax but it failed
7
3836
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
6
2299
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not work: it seems that < is not a valid character, so the beginning of the word starts at theletter 'p' instead of '<'. Because I'm not an expert in regular expressions, maybe someone of you guys can help me? I need the correct regex to find the...
3
2569
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular expression. ^(.+?) uses (?!a spoon)\.$
25
5194
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.