There are 3 numbers allowed 10,20,35

You need to make a regular expression so that any combination of these numbers is appropriate, that is:

10,20,35; 35,10,20; 20,35,10; 

etc.

Tell me, please, what will this regular expression look like?

  • Are you sure you want to work with a string of text in your task? - Sergiks

2 answers 2

The most correct in this situation would be to use backreference to remove from the match already matched alternatives.

 (10|35|20),(?!\1)(10|35|20),(?!\1|\2)(10|35|20) 

or more beautiful entry form:

 (10|35|20),(?!\1)((?1)),(?!\1|\2)((?1)) 
     ^(10|20|35)([\\,])(10|20|35)([\\,])(10|20|35)$ 
    • It is possible and shorter to do ^ (10 | 20 | 35 |,) {5}; $, but so and so will find options like 10,10,10 - Veliant
    • one
      Your variant will even find 5 commas, @Veliant :) unlike the code above. - KoVadim