[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

Regular Expression up to an alpha character

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
thomashospital
Asked:
thomashospital
  • 3
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
^(\d++)

will match all the digits upto something that isn't a digit.
0
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now