0

I want to check that a String is pipe-generated numbers. There should be numbers between pipes.

  • Valid Strings examples: 300, 300|600.
  • Invalid Strings examples: 300||||600

I tried ^([\d|\d])*$. However, this still said that 300||||600 is a valid String.

Holger Just
  • 49,152
  • 14
  • 106
  • 117

1 Answers1

1

Here, what you want is one number, ie \d+, followed by an undetermined number of occurrences of a pipe then a number, which would be (\|\d+)* (the pipe is escaped).

As you want it to cover the whole input this would be

^\d+(\|\d+)*$
Denys Séguret
  • 355,860
  • 83
  • 755
  • 726