Solved

Help with Regex 2

Posted on 2012-04-04
8
309 Views
Last Modified: 2012-07-30
Hello Again EE,

Mostly for Kaufmed and TerryOpus,


with that regex:

(?<=GL_)\d+-\d+|(?<=GR_).*


what if I would like the dash to be optional after GL_  ? (dash is between some numbers)
also It might happen there would be more dashes like this:


GL_100-390-3992-1 (several dashes)
or this:
GL_9383-1384  (1 dash)
or this:
GL_1900000    (no dash)
0
Comment
Question by:PhilippeRenaud
  • 3
  • 3
8 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 37806031
To match the dash 0 or 1 times:

(?<=GL_)\d+-{0,1}\d+|(?<=GR_).*
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37806041
what if 0,1,2,3,4,5,....999 ?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 37806076
You want to match the number if the dash is there or if it is not.  If it is there, it will not be there more than once.  So we need to match the dash 0 or 1 time. The matching of digits has not changed.  Try it for yourself.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37806087
Its not working if I try with this :


GL_103923-323-433334


the match will be only on :   103923-323

result would need to match:    103923-323-433334
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 37806121
Okay, I see what you mean.  My mistake in reading your question. You really want to match multiple sets of digits and hyphens if present...

(?<=GL_)[\-\d]+\d+|(?<=GR_).*

If you don't care if the last digit is also a hyphen:

(?<=GL_)[\-\d]+|(?<=GR_).*
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 37806138
Thanks !
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37806157
For the multiple digit-hyphen combos:

(?<=GL_)\d+(?:-\d+)*|(?<=GR_).*

Open in new window

0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS Feed MS SQL Server Stored procedure with loop 4 37
VB.Net. Reading xml value 6 30
VB.net Open video relating to control 2 20
CC Dreamweaver Regular Expression Problem 14 19
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 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