0

I am trying to match the the numbers, where some could be with or without a hyphen "-"

example one: 1: 3

example two: 24: 9-7

I tried the following:

(\d+): ((\d+)-(\d+)|(\d+))

and replace with:

A=\1\nB=\2\nC=\3\n

It works well for the first example, but not for the one with the hyphen. It gives the output:

A=24
B=9-7
C=9

Where it should be:

A=24
B=9
C=7

When I tried this:

(\d+): (?:(\d+)-(\d+)|(\d+))

the second one was OK, but not the first.

Mike
  • 2,051
  • 4
  • 28
  • 46

0 Answers0