I have an array of bytes, I need to check if it starts with a specific number 0, terminates with 9 and in-between could be anything numbers, but after 9, I get the sum of the numbers.
e.g test[] = { 0, 1, 4, 5, 9, 10 };
test[] = { 0, 3, 2, 9, 6, 0, 4, 2, 9, 6 }; - in this there are two sets
Is there way using Regular Expression to find this?
This doesn't look like a regular language to me, so the answer is no, you can't do it.
If the size of the list was fixed or you needed the sum of the numbers modulo 10 for example, it would be very complicated, but probably doable. In general though, a language in which the words consist of a list of numbers and the sum of them isn't regular, as it trivially fails to satisfy the pumping lemma.
On the positive side, it can easily be done without regular expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With