at night, after saying my prayers, i typically count sheep to help me fall asleep.
i want a regular expression to help me with the correct count.
i want the following strings to match
0
1sheep
2sheepsheep
3sheepsheepsheep
and so on.
what is the regular expression for this?
something like '(\d+)(sheep){\1}' if {\1} would do what i want it to do
what if i count my sheep in pairs (1sheepsheep and 2sheepsheepsheepsheep), what would the regular expression be then?
Python’s regular expression engine does not support parsing a matched subexpression to a repetition count, and I don’t think this should be done with RegExp either.
The best bet is to combine RegExp matching and checking with code: