Solved

# Regular Expression Ideas

Posted on 2011-05-09
286 Views
Last Modified: 2013-12-16
I need to validate input into a textblock, and I'm I'm think a regular expression might be suitable.

The criteria is as follows:

numeric . (AV or AI or SCH)numeric

e.g. 1234.AV4321 or 18327.AI1928 or 10293.SCH1928

The first digit of the numeric parts can not be a zero. 01929.AV01929 is not a valid input.

Any ideas?
0
Question by:wint100
4 Comments

LVL 18

Expert Comment

Play with this tool:
Expresso 3.0
http://www.ultrapico.com/Expresso.htm
0

LVL 74

Expert Comment

Try:
``````^[1-9]\d*\.(?:AV|AI|SCH)\d+\$
``````
0

LVL 74

Assisted Solution

Correction:
``````^[1-9]\d*\.(?:AV|AI|SCH)[1-9]\d*\$
``````
0

LVL 23

Accepted Solution

The Regex to validate that pattern is as follows:

var pattern = new Regex(@"^[1-9]\d*\.((AV)|(AI)|(SCH))[1-9]\d*\$");

Here is a sample test:

``````var pattern = new Regex(@"^[1-9]\d*\.((AV)|(AI)|(SCH))[1-9]\d*\$");
var values = new string[]{"1234.AV4321","18327.AI1928","10293.SCH1928","01929.AV01929","1929.AV01929","01929.AV1929"};

foreach (var value in values)
{
Console.WriteLine("{0} = {1}", value, pattern.IsMatch(value));
}
``````

Output:

``````1234.AV4321 = True
18327.AI1928 = True
10293.SCH1928 = True
01929.AV01929 = False
1929.AV01929 = False
01929.AV1929 = False
``````

I hope this helps.
0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
This video discusses moving either the default database or any database to a new volume.

#### 729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!