Solved

Regular Expression up to an alpha character

Posted on 2010-09-10
3
480 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

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:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 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