Hi I have a list of ids separated with commas and I need to take the ids which are divisible to 3.
This cannot be done with a regex in any useful way.
Depending on your context you can use for example
(assuming the string
This regexp will match all numbers divisible by three:
Here is an example ipython session using this construct:
This can be done, although – if you are sure that your input only contains comma-separated integer numbers (and not, say, words) – the answer from Florian Diesch contains a saner way to do this.
Differences: Florian's answer will convert everything that is separated by commas into integers (can cause problem when the input is not well-formed), divide them and return them as integer if they work. The regex version will just scan the input for any numbers divisible by three (that have word boundaries on both sides) and return them as strings.