Solved

Regular Expression up to an alpha character

Posted on 2010-09-10
3
475 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:RQuadling
Comment Utility
^(\d++)

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

Accepted Solution

by:
RQuadling earned 500 total points
Comment Utility
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:RQuadling
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now