Solved

Regular Expression up to an alpha character

Posted on 2010-09-10
3
479 Views
Last Modified: 2012-05-10
I need to build a regular expression that will take a string and get all the numerics up to an alpha, then cut off everything from the alpha to the end including ending numerics.  The numerics up to the alpha can be between 8 and 11 positions.  Example:

12345678912S1C100

or it could be

12345678SC100

I want all the numerics at the beginning and i dont want any value after the S.  The beginning can be anywere from 8 positions to 11 positions.  I am doing this in a hospital system that can utilize regular expressions, so i dont want to do a seperate VB program to clean up the data.  
0
Comment
Question by:thomashospital
  • 3
3 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 33645488
^(\d++)

will match all the digits upto something that isn't a digit.
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 33645494
Ah. .NET doesn't support possessive quantifiers.


Dim ResultString As String
Try
      ResultString = Regex.Match(SourceString, "^(\d+)", RegexOptions.IgnoreCase Or RegexOptions.Multiline).Value
Catch ex As ArgumentException
      'Syntax error in the regular expression
End Try
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 33661304
If you are just starting out with Regular Expressions, then I can STRONGLY recommend a really useful tool from JGSoft called RegexBuddy.

The code you saw above, though whilst simple, was created using RegexBuddy.

It allows you to build regexes and then export them to different languages.

http://www.regexbuddy.com/

And with a "... risk-free with our 3-month unconditional money-back guarantee." you've got nothing to lose!!!

Hmmm. If the advertising police come in on this, I use the tool every day. I used it to help thomashospital. He can use it to help himself.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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:…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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

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

Join & Ask a Question