473,811 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression IsMatch question

This should be easy but I am brand new to regular expressions so hopefully
someone can help me. I want to do some simple field level validation in my
app and I can do a simple test to see if the value entered in a textbox
matches a value I am expecting -

RegEx.IsMatch(t extbox.text,"^L S$"). - So this will return true if my
textbox.text is "LS".

What I want to do though, is to know if the value in my textbox.text does
NOT match "LS".

I know this is lame because obviously I could just say:
if not(regex.ismat ch(textbox.text ,"^LS$") then....
but I am trying to right some dynamic code to do the validating and I don't
want to have to know if I am testing for true or false.

Does this make sense? Can anyone help me?
Jul 21 '05 #1
1 1602
"Kate Bieren" <ka***@bidtek.c om> wrote in
news:ec******** ******@TK2MSFTN GP09.phx.gbl...
This should be easy but I am brand new to regular expressions so hopefully
someone can help me. I want to do some simple field level validation in my
app and I can do a simple test to see if the value entered in a textbox
matches a value I am expecting -

RegEx.IsMatch(t extbox.text,"^L S$"). - So this will return true if my
textbox.text is "LS".

What I want to do though, is to know if the value in my textbox.text does
NOT match "LS".

I know this is lame because obviously I could just say:
if not(regex.ismat ch(textbox.text ,"^LS$") then....
but I am trying to right some dynamic code to do the validating and I
don't
want to have to know if I am testing for true or false.


This really isn't as easy as it should be: The "standard" way to do it would
be using alternations like this:

^(.{0,1}|[^L].|.[^S]|.{3,})$

Read: zero or one character, or anything but an L followed by one character,
or one character followed by anything but an S, or more than 2 characters.

Luckily MS included a special Regex construct that makes this kind of thing
a lot easier: Negative lookahead assertions:

^(?!LS$).*

The (?!...) part tests if the subexpression does not match. If it does, the
rest of the expression is evaluated, and .* always matches.

BTW: Do you know Expresso? (www.ultrapico.com)

Niki
Jul 21 '05 #2

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

Similar topics

5
2337
by: Henry | last post by:
I have this simple code, string escaped = Regex.Escape( @"`~!@#$%^&*()_=+{}\|;:',<.>/?" + "\"" ); string input = @"a&+" + "\"" + @"@(-d)\e"; Regex re = new Regex( string.Format(@"(+)", escaped), RegexOptions.CultureInvariant ); string s = re.Replace( input, "" ); It doesn't seem to work, regular expression return without filter out any character
4
1760
by: Arne | last post by:
Hi, I'm trying to recognise phone numbers on the following format using regular expressions: +47 123 45 678 This should be recognised by the following regular expression: +47 \d{3} \d{2} \d{3} but it's not. This regular expression: +47 \d{2} \d{2} \d{2} \d{2} DOES recognise the following phone number: +47 12 34 56 78
5
263
by: Amy L. | last post by:
I was looking at some Regular Expressions and I noticed some of them have the following character in them "/i". For example: \b(?:college|university)\s+diplomas/i In the .Net documents I can't seem to find any reference to /i - can someone tell me exactly what /i does and if it is supported in the .Net regular expression parser? Amy
2
239
by: Ron Vecchi | last post by:
I'm tring to figure out the expression to use to search a bunch of documents that contain a word but do not contain a different word. Not having any luck though! Any ideas Thanks for the help
3
1445
by: rodchar | last post by:
hey all, what would my expression look like if i wanted to make sure that the input matched the following pattern. c:\filename.ext it doesn't have to be the c drive just a letter, colon, filename, and extension.
3
266
by: Richard Wilde | last post by:
How do i match and return true for this string as a regular expression? Gdd_dd Where dd is a single digit Can anyone help me? Thanks Rippo
1
1105
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in VB.Net-
1
285
by: Kate Bieren | last post by:
This should be easy but I am brand new to regular expressions so hopefully someone can help me. I want to do some simple field level validation in my app and I can do a simple test to see if the value entered in a textbox matches a value I am expecting - RegEx.IsMatch(textbox.text,"^LS$"). - So this will return true if my textbox.text is "LS". What I want to do though, is to know if the value in my textbox.text does NOT match "LS".
5
3792
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+), City of, (?<OrgState>(()|( +\.)))( \((?<OrgCountry>{2,})\))?$ (ignore the line wrap)
0
9728
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
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10389
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
10402
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
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
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...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.