473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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(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".

I know this is lame because obviously I could just say:
if not(regex.ismatch(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 1576
"Kate Bieren" <ka***@bidtek.com> wrote in
news:ec**************@TK2MSFTNGP09.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(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".

I know this is lame because obviously I could just say:
if not(regex.ismatch(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
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),...
4
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}...
5
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...
2
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...
3
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,...
3
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
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...
1
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...
5
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>(+)+),...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.