• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Help with Regex 2

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
PhilippeRenaud
Asked:
PhilippeRenaud
  • 3
  • 3
1 Solution
 
PaulHewsCommented:
To match the dash 0 or 1 times:

(?<=GL_)\d+-{0,1}\d+|(?<=GR_).*
0
 
PhilippeRenaudAuthor Commented:
what if 0,1,2,3,4,5,....999 ?
0
 
PaulHewsCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
PhilippeRenaudAuthor Commented:
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
 
PaulHewsCommented:
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
 
PhilippeRenaudAuthor Commented:
Thanks !
0
 
käµfm³d 👽Commented:
For the multiple digit-hyphen combos:

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

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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