-1

I am interested to see if such regex can be created? For example, this regex will match exactly two of preceding token: ^((pi|e|x|([-]?[0-9]*[.]?[0-9]+)){2}), and I'd like to match such string as long as it has two or more of something inside.

//want to recognize
//piex14.3   -- will see pi, e, x, number of type double
//14e        -- will see number of type double, e
//12.5pi     -- will see number of type double, pi
//ex         -- will see e, x
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Rorschach
  • 734
  • 2
  • 7
  • 22

1 Answers1

5

From https://en.wikipedia.org/wiki/Regular_expression:

{min,} The preceding item is matched min or more times.

You should be able to use ^((pi|e|x|([-]?[0-9]*[.]?[0-9]+)){2,})

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • Thank you, I've tried it but it still can recognize `double` as only match, for example `1.6` gets matched. This is because I want to be able to recognize `.3` or `5.` as a number. So I'd need to work around that. – Rorschach Apr 24 '20 at 22:10
  • 1
    @Rorschach, take a look at https://ideone.com/iDIJTy. Is that not what you are trying to get? – R Sahu Apr 24 '20 at 22:27
  • @R Sahu. All your examples work fine, however, input line `2.4`, and you'll notice a match, even though it shouldn't be. Because of how I defined looking for a number of `double` type, but I would like to avoid changing that part. – Rorschach Apr 24 '20 at 23:07
  • 1
    @Rorschach, that points to the fact that you have not defined the regex correctly to meet your requirement. That's a different problem than the question you are asking -- how to specify 2 or more matches of the previous matched item. – R Sahu Apr 25 '20 at 03:59