Solved

Regular Expression up to an alpha character

Posted on 2010-09-10
3
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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